Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by rinceWind (Monsignor)
on Feb 16, 2007 at 16:20 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://600470]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-19 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found