Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How to get ($1, $2, ...)?

by rinceWind (Monsignor)
on Feb 16, 2007 at 16:20 UTC ( #600470=note: print w/replies, xml ) Need Help??


in reply to How to get ($1, $2, ...)?

I very rarely use $1, $2, etc. these days, as I find they're a source of bugs for the unwary. This is mainly owing to the very special type of binding, a consequence of which is that, in the event of a failure to match, they retain their previous values.

Instead, I capture to lexical variables. In your case, a single lexical array will do:

my @answers; my $re = qr/Title: (.*?), Author: (\w+) (\w+)$/; # 3 groups here while (my @results = $text =~ /$re/mgc) { my %ans; push @answers, \@results; }

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://600470]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2019-07-16 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?