Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: Regex conditional match if previous match in same expression is true?

by radiantmatrix (Parson)
on Apr 10, 2007 at 15:59 UTC ( [id://609185]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Regex conditional match if previous match in same expression is true?
in thread Regex conditional match if previous match in same expression is true?

Hm, I hadn't thought of using alternation in this way. Most helpful, thank you! My comments to ikegami apply to your post as well.

What do you mean by I was "getting the wrong thing"? I mean, I was attempting to print an undef value, which threw warnings... but was I really getting inaccurate results that way? Mind clarifying a little?

<radiant.matrix>
Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet
  • Comment on Re^4: Regex conditional match if previous match in same expression is true?

Replies are listed 'Best First'.
Re^5: Regex conditional match if previous match in same expression is true?
by demerphq (Chancellor) on Apr 10, 2007 at 16:50 UTC

    $1 is a dynamically scoped variable that contains details from the last successful match in the current scope. It is NOT set to undef after a failed match.

    Regarding your comments to ikegami, they dont seem so relevent here. I didnt use an eval operator, as for how to accomplish the goal with the conditional pattern and not alternation, well ive already done that havent I? If you mean regarding MRE, id say just work through the book. There is a way of thinking about things that makes regexes easy to understand, and there is a way that will lead to confusion. I dont recall specifically anything that gives a particularly good discussion of the conditional pattern. I have never encountered one in live code.

    ---
    $world=~s/war/peace/g

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found