in what array do all the $1,$2,... live?
in what array do all the $1,$2,... live?
am 30.09.2007 04:03:10 von Dan Jacobson
What is the name of the array where all the $1,$2,... live?
Or do I really need to gather them up manually:
@all_the_matches=($1,$2,$3,$4,$5,...);
man perlvar doesn't mention it.
Re: in what array do all the $1,$2,... live?
am 30.09.2007 04:30:25 von Paul Lalli
On Sep 29, 10:03 pm, jida...@jidanni.org 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
Re: in what array do all the $1,$2,... live?
am 30.09.2007 04:58:18 von Bob Walton
jidanni@jidanni.org wrote:
> What is the name of the array where all the $1,$2,... live?
> Or do I really need to gather them up manually:
> @all_the_matches=($1,$2,$3,$4,$5,...);
> man perlvar doesn't mention it.
Well, you can easily put them all in whatever array you want:
use strict;
use warnings;
my $string='abc';
my @array=$string=~/(.)(.)(.)/;
print join ':',@array;
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
Re: in what array do all the $1,$2,... live?
am 01.10.2007 14:43:43 von nobull67
On Sep 30, 3:03 am, jida...@jidanni.org wrote:
> What is the name of the array where all the $1,$2,... live?
> Or do I really need to gather them up manually:
> @all_the_matches=($1,$2,$3,$4,$5,...);
> man perlvar doesn't mention it.
This has been discussed here recently
http://groups.google.com/group/comp.lang.perl.misc/tree/brow se_frm/thread/66e4e634e618da51/8b84cfd95af097ce