in reply to Short-circuiting a map list.
Is this anything close? I'm not using map, and it's not pretty when dealing with undefined values, but it stops evaluating list arguments when it hits the match value. Perhaps it could be massaged into something you want.
$ cat 930256_a.pl #!/usr/bin/perl use strict; use warnings; #my @list = (5, undef, 1 .. 9); my @list = (5, 1 .. 9); sub xmap { my $match = shift; my $rc = shift; my @rv=(); for (@_) { push @rv, &$rc($_); last if $_ eq $match; } return @rv; } print "list: ", join(", ", @list), ".\n"; print "xmap: ", join(", ", xmap(7, sub { $_*2 }, @list)),".\n"; $ perl 930256_a.pl list: 5, 1, 2, 3, 4, 5, 6, 7, 8, 9. xmap: 10, 2, 4, 6, 8, 10, 12, 14.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Short-circuiting a map list.
by BrowserUk (Patriarch) on Oct 08, 2011 at 02:09 UTC |