Hi,all great monks,I need your wisdom to help me.

I created a hash in SDBM_File.And one of its value is reference(ARRAY,HASH,whatever).It's failed when I dereference it to its original values,perl tell me it's undef.I researched it,then I found when I give a reference to a hash key,the hash just write the literal mem address into SDBM_File(e.g. 'ARRAY(0x123456)').when I read this key's value, it just give me the literal address string,and tell me it's not a ref.

use Fcntl; use SDBM_File; tie(%h,'SDBM_File','foodbm',O_RDWR|O_CREAT,0640) || die $!; $h{'a'}=1; %h{'b'}=[2,3]; if (ref $h{'b'}) { print "it's a ref,ok\n"; # perl will not print this! } else { print "it's not a ref,just $h{'b'}\n"; # this is what perl printed! } if (!defined $h{'b'}->[0]) { print "\$h{'b'}->[0] not defined!\n"; # perl also print this! } untie(%h);
Please tell me how can I store array ref or hash ref into SDBM_File and restore it to its original values. Thank you!

In reply to hash in SDBM_File by camelry

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.