Cambo has asked for the wisdom of the Perl Monks concerning the following question:
This is an initialization routine I'm using as part of allowing *trusted* user configuration for a script (cut down to see the problem, obviously). Run as is, a newline is output. Adding the line $value; immediately prior to the eval leads to the correct result, however. I've found a workaround, but re-reading perlsub leads me to believe this is broken behavior. Has anyone else seen anything similar? This is 5.8.4, running on Linux. Thanks, CamboFile driver.pl: use strict; use TestMeNow; my %map = TestMeNow::initialize('value', 'Here I am!'); &{$map{'onecase'}{'ex'}}(); File TestMeNow.pm: use strict; package TestMeNow; my(%map, $value, %mapping); $map{'value'} = \$value; sub initialize { my(%args) = @_; foreach(keys %args) { ${$map{$_}} = $args{$_}; } my $string = <DATA>; %mapping = eval $string; return %mapping; } 1; __DATA__ 'onecase', { 'ex' => sub {print "$value\n";} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File-scoped lexicals and eval scope?
by dave_the_m (Monsignor) on Nov 08, 2007 at 23:28 UTC | |
by ysth (Canon) on Nov 09, 2007 at 04:51 UTC | |
by jbert (Priest) on Nov 09, 2007 at 11:12 UTC | |
by Cambo (Initiate) on Nov 09, 2007 at 17:19 UTC | |
by ysth (Canon) on Nov 11, 2007 at 03:57 UTC | |
by jbert (Priest) on Nov 11, 2007 at 22:12 UTC | |
| |
|
Re: File-scoped lexicals and eval scope?
by moritz (Cardinal) on Nov 08, 2007 at 23:04 UTC | |
by Cambo (Initiate) on Nov 09, 2007 at 17:15 UTC |