Re: in what array do all the $1,$2,... live?



On Sep 29, 10:03 pm, jida...@xxxxxxxxxxx wrote:
What is the name of the array where all the $1,$2,... live?

There isn't one by default.

Or do I really need to gather them up manually:
@all_the_matches=($1,$2,$3,$4,$5,...);

You can. You don't need to.

man perlvar doesn't mention it.

No, but perlop tells you:

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...).

So just evaluate your pattern match in list context (ie, assign it to
an array), and you've got your $1, $2, $3, etc variables:

my $str = "foo bar baz";
my @matches = $str =~ /(\w+) (\w+) (\w+)/;
# @matches = ('foo', 'bar', 'baz)

Paul Lalli

.



Relevant Pages