Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: grep flip flop (range operator)

by frozenwithjoy (Priest)
on Sep 13, 2012 at 07:12 UTC ( #993387=note: print w/replies, xml ) Need Help??

in reply to Re: grep flip flop (range operator)
in thread grep flip flop (range operator)

BONUS STUMPER: For all of the ones that don't print, they do print if you replace 1 with 0; however, all elements are printed instead of stopping at Q (shown below). For the one that did print, the change to 0 causes it to not print. Anyone able to explain this?

a b c Q r s

Replies are listed 'Best First'.
Re^3: grep flip flop (range operator)
by davido (Archbishop) on Sep 13, 2012 at 07:23 UTC
    perl -E 'say "Yes!" if $. == 0;'

    $. uninitialized if there's no file open for reading (undef). undef is false. In a numeric comparison, undef is promoted to zero (or conceptually better, zero is demoted to false, and undef is promoted to false). Consequently, 0 .. is true, and the flip flop flips.

    If warnings were enabled you'd get one. :)


      Ah, yes.... and the reason it doesn't stop at Q is because it gets flipped right back on after Q. Apparently, my brain only works once per night. Thanks!
Re^3: grep flip flop (range operator)
by grizzley (Chaplain) on Sep 13, 2012 at 08:51 UTC
    Whole list is printed, as after spotting 'Q' flip-flop goes to 'false' state and back to condition $. == 0 which is all the time true, so it sets flip-flop again to true.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993387]
[erix]: ( dutch certainly changes under the continuous onslaught of english, in sentence structure as well as vocabulary )
[erix]: I do some work as a corrector (if that's the right word) and often I have to remove phrases that people think is dutch but that is really literally taken from english (and does not exist in dutch. Although at some point it becomes acceptable, of course)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-03-19 22:20 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.