When you execute the statement $hash{toby}{ip} = '111'; on a newly created (and tied) hash, you are asking perl to
- Create a key named 'toby' in the hash (named '%hash').
- Set the value associated with that key to a new, empty, untied anonymous hash.
- Create a new key named 'id' in that anonymous hash.
- Set the value associated with that key ('id') to the string '111'.
The actual sequence perl performs thise steps is probably different, but they must all be performed.
In other words, the assignment $hash{toby}{id} = '111'; isn't an assignment to the hash %hash;
It is an assignment to the key 'id', within the anonymous hash that is the value of the key 'toby' within the hash %hash.
As %hash is newly created and the key 'toby' does not exist, perl has to 'autovivify' (ie. create) the key 'toby' and assign an anonymous hash to it, before it can create the 'id' key and assign '111' to it.
Not sure if that clarifies anything?
The short answer to "Could this be problem 'cause it is not one-level-hash..", is Yes!.
If you want to tie a multilevel hash, you would have to inspect the values STOREd into your base-level hash, and if they are hash references, tie these also. This is non-trivial to get right.
Hope that help is some way:)
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.