At 08:58 -0400 10/20/03, Mark Jason Dominus wrote:
>Dave Mitchell <davem@fdgroup.com>:
>> This isn't a bug, it's a feature :-)
>>
>> sub () {$lexical} is a constant sub generator, ie each call to 'sub'
>> returns a new constant sub rather than a closure.
>
>Oh well, so much for the principle of least astonishment.
>
>What's the workaround for this feature?
Dropping the prototype seems to work:
my $foo = 'foo';
my $get = sub {$foo}; # look, no prototype!
my $set = sub ($) {$foo = $_[0]};
$set->('bar');
print "foo = $foo = ".$get->()."\n";
__END__
foo = bar = bar
Liz