As another method, Data::Dumper works quite well in my shop
and we are regularly storing very complex data structures.
It works something like this, where $donor is a reference
to a complex structure
sub Clone {
my $donor = shift;
my $file = shift;
my ( $dna, $clone );
local $Data::Dumper::Indent = 0; # It will be eval'd, we don't n
+eed pretty
local $Data::Dumper::Purity = 1; # make sure all code is present
local $Data::Dumper::Terse = 1; # makes the eval work well
local $Data::Dumper::Deepcopy = 1; # tell Dumper our intent
#---
# Interestingly enough, Dumper will embed the call to bless in the
+ DNA.
# Which makes this whole analogy really quite accurate and somehow
+ strange
#---
$dna = Dumper( $donor );
#---
# At this point, the data structure in $donor is stringified
# into $dna. $dna can be written to file or whatever.
# To get it back out, do something like what follows -
# this is a cloning function, after all.
#---
$clone = eval $dna;
return $clone;
}
mikfire
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.