Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Determining which pattern matched

by ikegami (Patriarch)
on Apr 05, 2010 at 22:23 UTC ( [id://832934]=note: print w/replies, xml ) Need Help??


in reply to Re: Determining which pattern matched
in thread Determining which pattern matched

Use local our instead of my for variables declared outside of a (?{}) and (??{}) but used inside of them. It's much safer. Your second snippet won't work if it's moved into a function, for example.

Replies are listed 'Best First'.
Re^3: Determining which pattern matched
by rubasov (Friar) on Apr 05, 2010 at 22:42 UTC
    I've just wanted to demonstrate the technic without much clutter, but you're absolutely right. I should take care to demonstrate the best practice which is using local our instead of my along with (?{ }).

    Here's a great thread explaining the reason behind this for the interested monks (including ikegami's notes): Regexes: finding ALL matches (including overlap).

      My comments in that thread were on an entirely different matter (handling backtracking through (?{}), which isn't an issue in the code here), but blokhead mentioned the issue with lexicals in that thread.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found