M
Michele Dondi
The documentation is clear (and I'm not contending this!) about the
fact that closures are about *lexical* variables.
Thus I *do* understand why the following doesn't work as (I, for one,
could have) expected:
# perl -le 'print map $_->(), map { sub { $_ } } qw/f o o/'
CODE(0x8137f84)CODE(0x8137f84)CODE(0x8137f84)
BTW: OTOH I do *not* understand *how* exactly it fails to work, i.e.
what I actually get. Data:umper on
map { sub { $_ } } ...
gives me
$VAR1 = sub { "DUMMY" };
$VAR2 = $VAR1;
$VAR3 = $VAR1;
As a side note indeed this is *not* WIM...
However, to return to the main theme, using
map { my $t=$_; sub { $t } } qw/f o o/
instead does exactly what I want, again as of the documentation. But
IMHO the latter conveys the psychological feeling of being equivalent
to the former, just in a more clumsy form.
So I wonder wether, apart possible technical difficulties, there are
other issues against the possibility of having closures using $_.
Michele
fact that closures are about *lexical* variables.
Thus I *do* understand why the following doesn't work as (I, for one,
could have) expected:
# perl -le 'print map $_->(), map { sub { $_ } } qw/f o o/'
CODE(0x8137f84)CODE(0x8137f84)CODE(0x8137f84)
BTW: OTOH I do *not* understand *how* exactly it fails to work, i.e.
what I actually get. Data:umper on
map { sub { $_ } } ...
gives me
$VAR1 = sub { "DUMMY" };
$VAR2 = $VAR1;
$VAR3 = $VAR1;
As a side note indeed this is *not* WIM...
However, to return to the main theme, using
map { my $t=$_; sub { $t } } qw/f o o/
instead does exactly what I want, again as of the documentation. But
IMHO the latter conveys the psychological feeling of being equivalent
to the former, just in a more clumsy form.
So I wonder wether, apart possible technical difficulties, there are
other issues against the possibility of having closures using $_.
Michele