I use Perl only occassionaly and hope that question isn't too trivial.

I got a file 'func_data' with a stored hash structure called FuncAssociateData
(but I don't know how the file was originally created :( ).

The first line of the file looks like:
pst0^D^D^D1234^D^D^D^H^Q^QFuncAssociateData^C^D^@^@^@^D^C{^\^@^@

and I can read the content of the file func_data using:

use Storable; %FuncAssociateData = %{ retrieve("func_data") };
and than use the hash without problem.

If I read the file content with

$href = retrieve("func_data"); print "HREF: $href"
I get
HREF: FuncAssociateData=HASH(0x8206554)

---

My problem starts, when I try to store the hash structure again in a file using:

use Storable; store(\%FuncAssociateData ,"new_func_data");

The file format looks similar, but not identical to the original file and the first line in this file looks like:
pst0^D^F^D1234^D^D^D^H^C^D^@^@^@^D^C{^\^@^@

Note that in contrast to the original file the name of the hash variable 'FuncAssociateData' is missing
and if I read the content with

$href = retrieve("new_func_data"); print "HREF: $href"
it gives
HREF: HASH(0x8206578)

How do I store a hash structure in a file, so that it is stored in the format as in the original file (including the name of the variable containing the hash) ???

e.g.
pst0^D^D^D1234^D^D^D^H^Q^QFuncAssociateData^C^D^@^@^@^D^C{^\^@^@
and NOT just
pst0^D^F^D1234^D^D^D^H^C^D^@^@^@^D^C{^\^@^@

The program using this data file works only with the first format, not with the second one.
Thanks.


In reply to Storing hash to disk with variable name by guu

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.