[VPM] regex found matches array

peter at psdt.com peter at psdt.com
Sun Mar 1 19:15:57 PST 2009


> Jer A wrote:
>> How do i retrieve the "groups" array, from the regex query that contains
>> the groups in $1 $2 $3 ...etc . the script has no hardcoded knowledge of
>> the regex pattern, as it is read from a string into a $var, which is
>> evaluated like this /$var/eg.
>>
>> Thanks in advance for all help....I hope you can understand, as I find
>> it hard to explain.
>
> Say something like this:
>
>    my $results = [$source =~ m/$pattern/g];
>
> Then the $results array has one element per capture by the pattern.

s/array/arrayref/.

Any reason not to skip the enreferencing?

my @results = ( $source =~ m/$pattern/g );

> Make sure the whole pattern-match expression is in list context (such as
> my
> array value constructor provides) or otherwise it will just (in scalar
> context)
> return the count of matches.
>
> -- Darren Duncan





More information about the Victoria-pm mailing list