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.
Please tell me how can I store array ref or hash ref into SDBM_File and restore it to its original values. Thank you!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);
In reply to hash in SDBM_File by camelry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |