Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Save all but line 32!

by BrowserUk (Pope)
on Sep 18, 2002 at 22:23 UTC ( #199022=note: print w/replies, xml ) Need Help??


in reply to Re: Save all but line 32!
in thread Save all but line 32!

I've read those paragraphs at least a dozen times since I first saw reference to the "flip-flop operator" in the spoiler for an obfu, one of erudil's or maybe on of yours, and I still have trouble applying it.

If anyone has a less wordy, more .. um .. transparent description of the .. and ... in a scalar context, or even better a simple example of use that is self-contained and demonstrative, I for one would find that very useful.


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Replies are listed 'Best First'.
Re: Re: Re: Save all but line 32!
by blokhead (Monsignor) on Sep 19, 2002 at 06:18 UTC
    I managed to come up with the following code that is not quite groundbreaking, but which you may find useful. The '..' expression is false until first_condition is true (until $i == 3). It continues to be true until second_condition is true (the next number which is 3 mod 10). Playing around with the *_condition functions will help get the hang of things. It helped a bit for me -- I still am not entirely comfortable with the operator (at least in scalar context) myself, but I'm getting there.

    In Abigail-II's code, 32..32 is syntactic sugar for $.==32 .. $.==32. So when $. is equal to 32, the expression becomes true, and then becomes false for all subsequent evaluations. The unless reverses the logic so that each line of input is printed only if it's not #32. I like it!

    use strict; for my $i (0 .. 20) { if (first_condition($i) .. second_condition($i)) { print "true for $i\n"; } else { print "false for $i\n"; } } sub first_condition { return $_[0] == 5; } sub second_condition { return $_[0] % 10 == 3; } __END__ false for 0 false for 1 false for 2 false for 3 false for 4 true for 5 true for 6 true for 7 true for 8 true for 9 true for 10 true for 11 true for 12 true for 13 false for 14 false for 15 false for 16 false for 17 false for 18 false for 19 false for 20

    blokhead

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2020-10-31 23:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (291 votes). Check out past polls.

    Notices?