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

Re: Matching against $_ behaves differently than matching against a named scalar?

by rsFalse (Chaplain)
on Apr 23, 2020 at 21:53 UTC ( [id://11115987]=note: print w/replies, xml ) Need Help??


in reply to Matching against $_ behaves differently than matching against a named scalar?

A possible way to overcome it without using a lexical variable inside a loop: to make a successful match to reset $1, $2...
/^([^ ]+) ([^ ]+)/ or /(*ACCEPT)/; # or /(?=)/; print "$1 $2" . "\n" if $1 && $2;
Also, it is possible to 'control flow', being inside regex:
/^([^ ]+) ([^ ]+)(?{ print "$1 $2" . "\n" })/;
That way of using regex (with (?{ <code> }) construct) is useful for debugging.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-29 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found