As I said earlier, thawing the data was the hard part. Because yours fails if you use strict. By putting in a "print $@" right after the eval, and enabling strict, you'll see:

Global symbol "$VAR1" requires explicit package name at (eval 1) line +1, <$in> line 1.
Not good. The trick? Change your eval line to:
my $h = eval 'my ' . do { local $/; <$in> };
We get a lexical "$VAR1" which allows the whole thing to compile. Things don't work so well if you're dumping multiple variables, though. With multiple variables, you either pre-declare all variables using my (or our, or use var), or you split on ;, and put a "my " in front of each variable. The former is dangerous in that you may fail to predeclare some variable, the latter in that a semicolon may show up elsewhere in the data. So it's best to count on a single variable anyway.


In reply to Re^2: 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.