Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: A regex BR variable dead in following line/command

by LanX (Saint)
on Nov 12, 2021 at 16:40 UTC ( [id://11138763]=note: print w/replies, xml ) Need Help??


in reply to Re: A regex BR variable dead in following line/command
in thread A regex BR variable dead in following line/command

> Also, using $2 as a loop condition smells a bit fishy

Indeed, the idiomatic expression is rather

while( m/REGEX/g ) { ... # use groups only if match successful }

The only reason to check $2 separately, is to make sure it's not false ( "", 0, undef, etc )

this can be done with

while( m/REGEX/g ) { last unless $2; ... }

tho I doubt the OP is aware of all those false cases.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 19:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found