in reply to Short-circuiting a map list.
If you look at the output below, the while loop is entered ('a') just one at the top.
The map is entered ('b') just 6 times as required.
If you look at the bottom, of the output, 'just' the required values are returned.
There is just the minor irritation of the weirdness marked '#??'.
sub a{ my $x = shift; while(1){ print 'a'; map { print 'b'; last if $_ == $x; $_; } @_; print 'c'; }; } my @data = 0 .. 9; print for a( 5, @data ); __END__ c:\test>junk a b b b b b b 0 ##?? 1 ##?? 2 ##?? 3 ##?? 4 ##?? 5 ##?? 6 ##?? 7 ##?? 8 ##?? 9 ##?? 0 1 2 3 4
I guess I was hoping for some of the legendary PM inventiveness?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Short-circuiting a map list. (This works! But ...)
by Anonymous Monk on Oct 08, 2011 at 15:13 UTC | |
by BrowserUk (Patriarch) on Oct 08, 2011 at 15:21 UTC | |
by Anonymous Monk on Oct 08, 2011 at 15:33 UTC | |
by BrowserUk (Patriarch) on Oct 08, 2011 at 15:40 UTC | |
by Anonymous Monk on Oct 08, 2011 at 15:49 UTC | |
by ikegami (Patriarch) on Oct 08, 2011 at 18:15 UTC | |
by BrowserUk (Patriarch) on Oct 08, 2011 at 18:29 UTC | |
by ikegami (Patriarch) on Oct 09, 2011 at 05:18 UTC | |
|