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
};
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|