Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Initializing an anonymous hash

by davies (Parson)
on Mar 30, 2012 at 15:35 UTC ( #962637=note: print w/replies, xml ) Need Help??


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
    Thanks for your help and for introducing me to eval. I will do some reading.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://962637]
help
Chatterbox?
[stevieb]: A couple of years ago I went to Curacao on a business trip which is a few parallels south of Canary Islands, but one thing I liked was it was 90 degrees at all times consistently. Much different experience than living in Canada :)
[choroba]: Yeah, my wife sent me some pictures of the children yesterday, and there was snow all around. 10 days in Saigon and I totally forgot what weather they have back there.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (14)
As of 2017-02-23 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (349 votes). Check out past polls.