# Eval in Closure # Accessing lexical by name? # use strict; sub alert { print @_,"\n"; } ; my $getset; my $change =sub { my $it=shift; $getset->($it,"post"); }; my $x="global"; my $test=sub { my $x="pre"; $getset=sub { my ($name,$val)=@_; eval('$'.$name."='".$val."'"); # I can access any variable in this scope }; alert($x); # pre $change->("x"); alert($x); # post } ; $test->(); alert($x); # global