Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: unable to eval dumped hash

by haukex (Archbishop)
on May 02, 2020 at 09:54 UTC ( [id://11116349]=note: print w/replies, xml ) Need Help??


in reply to unable to eval dumped hash

Shameless plug: You might be interested in my module Data::Undump::PPI. It uses a static parse so it's safer than eval.

I dumped a hash into a file and then copied into the __DATA__section of my script.

Although I wouldn't recommend this for real-world use (use a config file instead), see my reply in the thread Is it possible to modify __DATA__ via the DATA file handle or otherwise? for a script that modifies its own __DATA__ section:

use warnings; use strict; use File::Replace 'replace3'; use Data::Undump::PPI qw/Dump Undump/; my $pos = tell DATA; my $data = Undump(fh => *DATA); $data->{counter}++; my (undef,$outfh,$repl) = replace3(__FILE__,':raw'); $repl->copy($pos); Dump([$data], fh=>$outfh); $repl->finish; __DATA__ $VAR1 = { counter => 0 };

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found