Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: unable to eval dumped hash

by kcott (Archbishop)
on Apr 28, 2020 at 08:01 UTC ( #11116151=note: print w/replies, xml ) Need Help??


in reply to unable to eval dumped hash

G'day nysus,

Writing the Dumper output to a file, manually opening that file, manually copying its contents, then manually pasting into a script, does not seem like a very sensible way to go. Even if you're using less manual steps — e.g. 'cat dumper.out >> script.pl' or 'G:r dumper.out' from 'vim script.pl' — I still wouldn't recommend it. You should not have to edit your code every time the data changes. Consider reading the Dumper output directly in your script.

"I tried getting rid of $VAR1 ..."

Perhaps Data::Dump would be a better choice:

$ perl -e ' use Data::Dumper; use Data::Dump; my $x = { a => 1, b => [1,2,3] }; print "*** From Data::Dumper ***\n"; print Dumper $x; print "*** From Data::Dump ***\n"; dd $x; ' *** From Data::Dumper *** $VAR1 = { 'b' => [ 1, 2, 3 ], 'a' => 1 }; *** From Data::Dump *** { a => 1, b => [1, 2, 3] }

Also take a look at Storable, JSON and YAML (those last two also have XS versions which will be faster).

— Ken

Replies are listed 'Best First'.
Re^2: unable to eval dumped hash
by nysus (Parson) on Apr 28, 2020 at 14:00 UTC

    Thanks, yes, I'm aware. My code is more or less an experiment on how to use the __DATA__ feature with dumped data. The data I dumped took several minutes to generate so I didn't really feel like re-running the code that generated it in the first place. Figured I'd try a "shortcut" which took longer than re-rerunning the code. But hey, I learned something.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2022-06-27 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (86 votes). Check out past polls.

    Notices?