Subject: | pairmap lexical vars inside coderef |
Running pairmap the variables inside anonymous sub "are not created" for each iteration as I would expected. Better with example:
use strict;
use warnings;
use List::Util qw(pairmap);
my @subs = pairmap {
my $v = "$a,$b";
sub {$v};
}
one => 'ONE', two => 'TWO', three => 'THREE';
warn $_->(),"\n" for @subs;
This example displays
three,THREE
three,THREE
three,THREE
while I would expect
one,ONE
two,TWO
three,THREE
Is there any simple explanation for such behaviour (I admit it is probably not a typical usage of pairmap).
Similar example with map works as I expect:
my @subs = map {
my $v = $_;
sub {$v};
}
'one','two','three';
warn $_->(),"\n" for @subs;
displays
one
two
three