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

You are creating hash elements with undef @a{@b}. This is called autovivication (see wikipedia for a nice explanation) and has nothing to do with the undef function. Something similar happens when you write @a{@b}= (1);. The hash would contain key a set to 1 and keys b and c set to undef

Replies are listed 'Best First'.
Re^4: Hash slice again
by targetsmart (Curate) on Jan 27, 2009 at 15:48 UTC
    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.

      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