in reply to Initializing an anonymous hash
eval works for me.
use strict; my $hash = {'MONTH' => 'January'}; print $hash->{MONTH} . "\n"; my $hashInitStr = "{'MONTH' => 'January'}"; # This would come from a f +ile my $hash1 = eval $hashInitStr; print $hash1->{MONTH} . "\n"
returns
Z:\Data\Perl>962633.pl January January Z:\Data\Perl>
Regards,
John Davies
Update: Be aware that this has hideous security implications. Also, as Moritz explained to me in reply to Testing error handling that calls "die", there are two forms of eval. But the code given above does what I think you say you want.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Initializing an anonymous hash
by Anonymous Monk on Mar 30, 2012 at 15:56 UTC |