metaperl has asked for the wisdom of the Perl Monks concerning the following question:
I need to set package variables in the package 'main' to the value of a key with the same name. I thought the code below would do it:
but printing the value of one of the globals after calling this sub does not yield anything, whereas it does in the warn right within this sub.sub globalize_weightframe { my ($i)=@_; warn "Globalize was passed $i."; my %w = %{$hangar->{stops}[$i]{weightframe}}; for my $val (keys %w) { eval "$main::$val = $w{$val}"; warn "globalize $val - $w{$val}"; } }
Any help on setting a set of package variables in this way is appreciated.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Setting package variables via eval
by BrowserUk (Patriarch) on Nov 09, 2011 at 22:39 UTC |
Back to
Seekers of Perl Wisdom