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

Re^2: extracting data

by moritz (Cardinal)
on Jun 27, 2012 at 08:25 UTC ( #978582=note: print w/replies, xml ) Need Help??

in reply to Re: extracting data
in thread extracting data

print "$def\n" if ! $val or $val =~ /^0|1$/;

Note that !$val already covers the case where $val is 0.

Also /^0|1$/ is not what you might think it is. The OR | in regexes has a looser precedence than concatenation, which means the regex is the same as ^0 OR 1$, so it also matches strings like 0foo or bar1.

The correct way to write it is /^(0|1)$/, or if you don't want to create a capture, /^(?:0|1)$/.

Replies are listed 'Best First'.
Re^3: extracting data
by kcott (Chancellor) on Jun 27, 2012 at 09:03 UTC

    ++ Thanks for spotting that. I've updated my node.

    I wasn't aware of the precedence issue: thanks for the good explanation.

    -- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978582]
[marioroy]: Lady_Aleena Angels on earth are real people. That's awesome.
[Lady_Aleena]: marioroy, what does MCE stand for in this instance? There are 3 pages of abbreviations to go through.
[Lady_Aleena]: ^ or Discipulus...
[marioroy]: Many-core Engine
[choroba]: MCE
[karlgoethebier]: is about to reach nirvana tonight...
[Lady_Aleena]: It could have meant a "Miserably Cute Event" or "Man Crush Everyday". 8)
[Corion]: choroba: Re the one-shot thing, I also thought of bit vectors and/or indexes into one common array from the hashes, but that makes maintenance of all these indices a chorse
[Corion]: *core
[Corion]: ** chore

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2017-05-29 08:28 GMT
Find Nodes?
    Voting Booth?