Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2022-01-28 22:44 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (74 votes). Check out past polls.