Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Data::Dumper and eval

by perlmonkey (Hermit)
on Sep 25, 2003 at 00:03 UTC ( #294040=note: print w/ replies, xml ) Need Help??


in reply to Data::Dumper and eval

Checking for $@ after both evals will reveal:
Global symbol "$VAR1" requires explicit package name at (eval 1) line 1.

To fix you can prefix your eval'd code with a 'my':

use strict; use Data::Dumper; { my $hashref = { "aaa" => 1, "bbb" => 2, "ccc" => 3, }; print "hashref : " . Dumper($hashref); my $dumped = Dumper($hashref); print "Dumped: $dumped\n"; my $restored = eval "my $dumped"; warn "\$@ = $@\n"; print "restored: " . Dumper($restored); my $test_2 = eval("my ".Dumper($hashref)); warn "\$@ = $@\n"; print "test_2: " . Dumper($test_2); }


Comment on Re: Data::Dumper and eval
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2015-07-05 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls