Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Flip-flop won't DWIM

by wu-lee (Beadle)
on May 21, 2009 at 15:58 UTC ( #765487=note: print w/replies, xml ) Need Help??


in reply to Re: Flip-flop won't DWIM
in thread Flip-flop won't DWIM

Right. Of course, silly me.

Ok, so this does what I want:

perl -lwe '$x = 1; print join " ", grep { scalar($x++../D/) } qw(A B C + D E F)' # prints: # A B C D
Although this is not particularly neat. Is there a better way?

Replies are listed 'Best First'.
Re^3: Flip-flop won't DWIM
by akho (Hermit) on May 21, 2009 at 16:15 UTC
    Your code prints "A B C D E F" for me, and I cannot see why it would print anything else.

    This seems to work if you insist on using flip-flop:

    $x = 1; print join " ", grep { $x..(($x=0) or /D/) } qw(A B C D E F);
    However, you could copy stuff from List::MoreUtils.
Re^3: Flip-flop won't DWIM
by wu-lee (Beadle) on May 21, 2009 at 16:13 UTC
    Actually, that doesn't, but this does:
    perl -lwe '$x = 0; print join " ", grep { scalar(!$x++../D/) } qw(A B + C D E F)' # prints: # A B C D
Re^3: Flip-flop won't DWIM
by ikegami (Patriarch) on May 21, 2009 at 16:57 UTC
    The "++" does nothing.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2023-09-28 01:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?