I'm sure someone will have some advice for me, too, here, but here is a snippet of some code I have for saving meta-information (basically, a hash in my situation). The _thaw method was the hardest to figure out (using both strict and warnings).
# snip... sub _lock_meta { my $self = shift; my $mode = shift || 'r'; my $meta_name = do { unless (exists $self->{metaname}) { $self->{metaname} = File::Spec->catfile($self->{path}, 'me +ta.info'); } $self->{metaname}; }; my $fh = IO::File->new($meta_name, $mode); if ($fh) { flock($fh, $mode eq 'r' ? LOCK_SH : LOCK_EX); } $fh; } sub _load_meta { my $self = shift; my $fh = $self->_lock_meta(); # only load it if it's been changed since the last load. my $s = stat($self->{metaname}); if ($s and $s->mtime() >= ($self->{metastamp} || 0) and $fh) { local $/; my $data = join '', $fh->getlines(); $self->{metastamp} = time(); $fh->close(); # release lock $self->{meta} = $self->_thaw($data); } } sub _save_meta { my $self = shift; my $fh = $self->_lock_meta('w'); $fh->print($self->_freeze($self->{meta})); $fh->close(); } sub _thaw { my $self = shift; my $data = shift; eval 'my ' . $data; } sub _freeze { my $self = shift; my $data = shift; require Data::Dumper; local $Data::Dumper::Indent = 0; join '', Data::Dumper::Dumper($data); } # snip...

In reply to Re: Need Example of Saving and Retrieving Hash from File by Tanktalus
in thread Need Example of Saving and Retrieving Hash from File by EchoAngel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.