morgon has asked for the wisdom of the Perl Monks concerning the following question:
Here is what I had thought to be an elegant solution:
And this acually work - the first time that is.sub blah { my($look_for, @array)=@_; my (undef, @elements_we_want) = grep { $_ eq $look_for .. 1 } @array; return @elements_we_want; }
The problem is the global state that the f**ing flip-flop operator holds and that does not get reset on calling the sub the second time.my @a = qw(hubba bubba abba zappa); blah("bubba", @a); # this gives qw(abba zappa) as desired
So my questions would be is there any elegant way to salvage the approach with the flip-flop or can someone recommend a better way of doing it?
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: flip-flop flop
by moritz (Cardinal) on Mar 30, 2012 at 10:03 UTC | |
by AnomalousMonk (Archbishop) on Mar 30, 2012 at 11:27 UTC | |
|
Re: flip-flop flop
by BrowserUk (Patriarch) on Mar 30, 2012 at 10:44 UTC | |
by morgon (Priest) on Mar 30, 2012 at 11:56 UTC | |
by BrowserUk (Patriarch) on Mar 30, 2012 at 12:10 UTC | |
by morgon (Priest) on Mar 30, 2012 at 13:07 UTC | |
by moritz (Cardinal) on Mar 30, 2012 at 13:31 UTC | |
| |
by BillKSmith (Monsignor) on Apr 01, 2012 at 13:47 UTC | |
|
Re: flip-flop flop
by kcott (Archbishop) on Mar 30, 2012 at 10:14 UTC | |
by JavaFan (Canon) on Mar 30, 2012 at 10:30 UTC | |
by kcott (Archbishop) on Mar 30, 2012 at 11:01 UTC | |
|
Re: flip-flop flop (reset)
by tye (Sage) on Mar 30, 2012 at 14:08 UTC | |
|
Re: flip-flop flop (be aware!)
by JavaFan (Canon) on Mar 30, 2012 at 15:09 UTC | |
|
Re: flip-flop flop
by remiah (Hermit) on Mar 30, 2012 at 23:03 UTC | |
|
Re: flip-flop flop
by Anonymous Monk on Mar 30, 2012 at 21:35 UTC | |
|
Re: flip-flop flop
by Anonymous Monk on Mar 30, 2012 at 23:07 UTC |