in reply to Re^2: Mini-Tutorial: Working with Odd/Even Elements
in thread Mini-Tutorial: Working with Odd/Even Elements
It will be a problem if you are running under strict. However, if the caller sets up $c as a package variable it will work.
sub map_triples(&@) { my $f = shift; my @res; no strict 'refs'; my $caller = caller; local(*{$caller."::a"}) = \my $a; local(*{$caller."::b"}) = \my $b; local(*{$caller."::c"}) = \my $c; push @res, $f->($a,$b,$c) while ($a, $b, $c) = splice @_, 0, 3; return @res; } use 5.010; use warnings; use strict; our $c; say for map_triples { $a + $b + $c } 1..12;
Good Day,
Dean
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Mini-Tutorial: Working with Odd/Even Elements
by LanX (Saint) on Jul 10, 2009 at 11:46 UTC |