Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: flip-flop flop

by BrowserUk (Pope)
on Mar 30, 2012 at 10:44 UTC ( #962562=note: print w/ replies, xml ) Need Help??


in reply to flip-flop flop

sub after{ my $target=shift; shift @_ until $_[0] eq $target; return @ +_ };; @a = 'a'..'z';; print after( 'm', @a );; m n o p q r s t u v w x y z print after( 'e', @a );; e f g h i j k l m n o p q r s t u v w x y z print after( 'y', @a );; y z

Add another shift if you don't want the element you looked for.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


Comment on Re: flip-flop flop
Download Code
Re^2: flip-flop flop
by morgon (Deacon) on Mar 30, 2012 at 11:56 UTC
    So far all approaches seem to avoid the flip-flop.

    It would be very curious to see if there is a way to reset the flip-flop in some sane way (you probably need to create a new closure to use in the grep every time you call it or something).

    This was one of the very few times I tried to make use of the flip-flop and more or less every time I try to use it I have to abandon it in the end.

    Because of this global-state issue the flip-flop is pretty much useless to me - to the point where I think perl would be better off without it...

      Because of this global-state issue the flip-flop is pretty much useless to me

      My take is that the flip-flop is very useful for one-liners were is compactness is invaluable, and I wouldn't want to lose that.

      But I cannot remember the last time I used in a script. What it does can always be done better -- though more verbosely -- when you have the space.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        From my point all it would take is a way to reset it's state somehow - then the flip-flop could be handy.

        Is there any reason why this functionality does not (seem to) exist?

      One way to "reset" the flip-flop is to recompile its statement.
      use strict; my @a = qw(hubba bubba abba zappa); print blah("bubba", @a), "\n"; print blah("bubba", @a), "\n"; sub blah { my($look_for, @array)=@_; my @elements_we_want; my $string = '(undef, @elements_we_want) = grep { $_ eq $look_for .. 1 } @a +rray;'; eval $string; return @elements_we_want; }
      Edit: Sorry, I did not notice the similiar idea by JavaFan.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-09-18 15:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (116 votes), past polls