note
Roy Johnson
<b>Update</b>: figured it out (simulthanks to Ikegami). Gotta reference the right package. Corrected solution:
<c>
sub map_pairs(&@) {
my $fn = shift;
my $pkg = caller;
map {
my $idx = $_ * 2;
no strict 'refs';
my ($a, $b)
= local (${$pkg.'::a'}, ${$pkg.'::b'})
= (@_[$idx,$idx+1]);
$fn->($a, $b);
} (0..$#_/2);
}
</c>
Previous, erroneous solution follows.
<p>
I think you made this harder than it needs to be. Isn't this equivalent?
<c>
sub map_pairs(&@) {
my $fn = shift;
map {
my $idx = $_ * 2;
local ($a, $b) = @_[$idx,$idx+1];
$fn->($a, $b);
} (0..$#_/2);
}
</c>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-300037">
<hr>
<small><b>Caution:</b> Contents may have been coded under pressure.</small>
</div></div>
778636
778724