Matt Lawrence wrote:
> 
> Jasper McCrea wrote:
> 
> >Paul Makepeace wrote:
> >
> >
> >>I'd like to dump regex matches into an array without explicitly naming
> >>$1, $2, ...
> >>
> >>=head1 NOT WORKING CODE
> >>    ($month, $day, $time, $host, $process, $pid, $message) =
> >>        /^(\w+) (\d+) (\d\d+:\d\d:\d\d) (\w+) ([()\w\/]+)\[(\d+)\]: (.*)$/ ||
> >>        /^(\w+) (\d+) (\d\d+:\d\d:\d\d) (\w+) ([()\w\/]+)():\s+(.*)$/;
> >>=cut
> >>
> >>I.e. if the first regex fails, try the other one.
> >>
> >>
> >>
> >
> >not tried, but if the first one fails, and produces nothing, why not just @a =
> >(//,//) ?
> >
> That'll probably get parsed as one big list. 

Uh-huh. It sure does. Yes. Indeed. That's the idea.

> Maybe without parenthesis
> the , operator will be parsed properly.

Can you define 'properly' for me? :)

The (//,//) method works (for I have ever so briefly tested it).

It's only a useful method if there isn't much overhead in doing the matches (and
in Paul's examples there isn't) and you always want the same number of matches.
If you were populating an array, rather than assigning to a list of variables,
you'd have to make sure if the first regex matched, the second wouldn't, and
vice versa. That might be too much trouble.

Jasper

Reply via email to