nop has asked for the wisdom of the Perl Monks concerning the following question:
The result isn't what I expected:use strict; use Data::Dumper; my %x = map { $_ => [$_, sub {shift;}]} qw(a b c); print Dumper(\%x);
Why do "b" and "c" share the same coderef as "a"? I had expected each would get a reference to their own sub.... Confused...$VAR1 = { 'a' => [ 'a', sub { "DUMMY" } ], 'b' => [ 'b', $VAR1->{'a'}[1] ], 'c' => [ 'c', $VAR1->{'a'}[1] ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: closure question
by chipmunk (Parson) on Feb 02, 2001 at 01:01 UTC | |
|
Re: closure question
by Fastolfe (Vicar) on Feb 02, 2001 at 01:53 UTC | |
by nop (Hermit) on Feb 02, 2001 at 02:23 UTC | |
|
Re: closure question
by runrig (Abbot) on Feb 02, 2001 at 01:00 UTC |