camelry has asked for the wisdom of the Perl Monks concerning the following question:
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash in SDBM_File
by rob_au (Abbot) on Feb 24, 2002 at 08:50 UTC | |
|
Re (tilly) 1: hash in SDBM_File
by tilly (Archbishop) on Feb 24, 2002 at 09:06 UTC | |
|
Re: hash in SDBM_File
by dws (Chancellor) on Feb 24, 2002 at 09:00 UTC |