jid...@jidanni.org wrote:
>In /bin/sh it merely takes a
>$ set a b c
>to set $1 $2 $3.
>
>So what is the easiest way to do the same in perl?
In Perl you would say: "Whenever you find yourself enumerating your
variables with numbers, then maybe it's a good time to think about using
an array instead". So take @foo and use
@foo = (a, b, c);
>Yes in perl they are related to regexps. No don't ask me why I want to
>set them,
Sorry, but that question is at the core of your problem. For all
practical purposes you should consider those variables read-only. Yes,
technically you can assign to them, but whenever you feel the urge to do
so normally there is a different, much better way.
>Just pretend I need to use them on the next line and want to
>try some different values.
Then why don't you use different variables like @foo[1], @foo[2], ... in
this next line?
>If it takes more than just a one-liner, then perl has problems.
-v, please
>$ perl -wle '"abc" =~ /(.)(.)(.)/; print $1, $2, $3;'
>abc
>
>Big drag.
>
>So we see on perlvar there is no array that can give us even read-only
>access to
> $<digits> ($1, $2, ...)
Why would you want to do that? The only time those variables are being
set is during a m// or s/// operation. And if you really want that list
of captured groups then you can easily capture your imaginary $<digit>
array:
Matching in list context
If the "/g" option is not used, "m//" in list context returns a
list consisting of the subexpressions matched by the parentheses
in the pattern, i.e., ($1, $2, $3...).
>not of course even to think of an easy way to set them by all directly by hand
>if we need to.
Why would you want to set them manually in the first place unless you
have some very unusual needs, e.g. interpreter-level debugging or
something like that?
>Well maybe perlvar should mention what the best way so-far to access
>them all (like /bin/sh's $@, $*), and set them all (like /bin/sh's set) is!
What for?
jue