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

  • Perl Peeves
    ... Unary "+" has no effect whatsoever, even on strings. ... to be using it in a scalar context already. ... That had effect but wasn't documented in "man perlop" in 5.005, ... -r File is readable by effective uid/gid. ...
    (comp.lang.perl.misc)
  • Re: Order of operations (was: FAQ 4.47 How do I handle circular lists?)
    ... Peter J. Holzer wrote: ... it is much less clear in the context of perlop. ...
    (comp.lang.perl.misc)
  • Re: Order of operations (was: FAQ 4.47 How do I handle circular lists?)
    ... it is much less clear in the context of perlop. ... undefined behaviour. ... Just because all implementations you have access to behave ...
    (comp.lang.perl.misc)
  • Re: Datagrid with search capabilities, how to implement it?
    ... We have a datagridview in a form and want to implement search capabilities ... Creates a currencymanager bound to the same binding context of the ... Uses the datatable.Selectmethod on the SortTable to get a datarow array ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: A question on string literals
    ... > context" in the first place, so that we can figure why: ... > foo = bar - one object context, ... A difficulty with the above is that the operand of sizeof ... sizeof &*array!= sizeof array ...
    (comp.lang.c)