Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Initializing an anonymous hash

by davies (Vicar)
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"


Z:\Data\Perl> January January Z:\Data\Perl>


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.

Comment on Re: Initializing an anonymous hash
Select or Download Code
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://962637]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2015-11-28 22:26 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls