in reply to Re: Mini-Tutorial: Working with Odd/Even Elements
in thread Mini-Tutorial: Working with Odd/Even Elements
I was surprised by the lack of such a function in List::MoreUtils recently. There is natatime, but it returns an iterator rather than using a callback.
I wonder how much speed you'd gain by replacing $f->($a,$b) with &$f. Another advanced feature for the collection!
It would be a nice bonus if you $a and $b were aliases to the args like with map.
sub map_pairs(&@) { my $cb = shift; my $caller = caller(); my $ap = do { no strict 'refs'; \*{$caller.'::a'} }; my $bp = do { no strict 'refs'; \*{$caller.'::b'} }; local *$ap; local *$bp; my @res; while (@_) { *$ap = \shift; *$bp = \shift; push @res, &$cb; } return @res; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Mini-Tutorial: Working with Odd/Even Elements
by Roy Johnson (Monsignor) on Jul 10, 2009 at 19:52 UTC | |
by ikegami (Patriarch) on Jul 10, 2009 at 20:14 UTC | |
by Roy Johnson (Monsignor) on Jul 10, 2009 at 23:40 UTC | |
by ikegami (Patriarch) on Jul 13, 2009 at 17:55 UTC | |
by LanX (Saint) on Jul 10, 2009 at 21:16 UTC | |
by Roy Johnson (Monsignor) on Jul 10, 2009 at 23:37 UTC | |
by ikegami (Patriarch) on Jul 16, 2009 at 18:32 UTC | |
Re^3: Mini-Tutorial: Working with Odd/Even Elements
by duelafn (Parson) on Jul 10, 2009 at 11:15 UTC | |
by ikegami (Patriarch) on Jul 10, 2009 at 14:13 UTC |