Playing with HASH references, I found a strange bug! Take look in the result of this code (tested with Perl-5.6.1 and Perl-5.8.0 on Win32):
my $hash = {} ;
$hash->{key1} = 'k1' ;
$hash->{key1}{key2} = 'k2' ;
print ">> $hash->{key1}\n" ;
print ">> $hash->{key1}{key2}\n" ;
__OUTPUT__
>> k1
>> k2
Note that the k2 ($hash->{key1}{key2}) is printed! But k1 ($hash->{key1}) already exist, and isn't a HASH ref!
What should happens is to exist only one option, k1 or k2! Not the both! I found the error using Storage, to save the HASH tree in a file. But Storage only save k1, like should be. In other words, k2 only exist in the memory, not in the HASH tree.
If you try to test the ref() of $hash->{key1} you also get undef.
Soo, is this documented? Is right or wrong? How to know if k1 is also a HASH ref?
Please, test the code and see if this output works in other OS too (tested on Win32 only).
Note that this only work for HASH reference, if you use %hash, work normal.
Graciliano M. P.
"The creativity is the expression of the liberty".
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.