in reply to Re^3: Hash slice again
in thread Hash slice again

I have read about Autovivification from http://en.wikipedia.org/wiki/Autovivification, actually I previously read this from "Intermediate perl" page number 44, which discusses about autovivification, but I just have not applied in this case. Thanks for pointing out
Explanation about autovivification,
Any nonexistent variable, or a variable containing undef, which we dereference while looking for a variable location(technically called an lvalue context), is automatically stuffed with appropriate reference to an empty item, and perl allows the operation to proceed. -- from "Intermediate Perl" by Randal.L.Schwartz, brian d foy, Tom phoenix.
this is also interesting http://www.sysarch.com/Perl/autoviv.txt

-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.

Replies are listed 'Best First'.
Re^5: Hash slice again
by ikegami (Patriarch) on Jan 27, 2009 at 16:36 UTC

    Any nonexistent variable, or a variable containing undef, which we dereference while looking for a variable location(technically called an lvalue context), is automatically stuffed with appropriate reference to an empty item

    That refers to

    $ perl -le'print $r||"[undef]"; $r->{x}; print $r||"[undef]";' [undef] HASH(0x814ec28)

    jethro was refering to a different kind of autovivification. Creating an alias (as undef does) to a non-existent array or hash element can create (vivify) the element in question (with value undef).

    $ perl -le'sub f {} print 0+keys %h; for ($h{x}) {} print 0+keys %h;' 0 1