Re: in what array do all the $1,$2,... live?
- From: Paul Lalli <mritty@xxxxxxxxx>
- Date: Sat, 29 Sep 2007 19:30:25 -0700
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
.
- References:
- in what array do all the $1,$2,... live?
- From: jidanni
- in what array do all the $1,$2,... live?
- Prev by Date: in what array do all the $1,$2,... live?
- Next by Date: Re: in what array do all the $1,$2,... live?
- Previous by thread: in what array do all the $1,$2,... live?
- Next by thread: Re: in what array do all the $1,$2,... live?
- Index(es):
Relevant Pages
|
|