in reply to Re^4: multiple values for one key in hash
in thread multiple values for one key in hash

How would autovivification know that the undef in lvalue context it's autovivifying wasn't the original undef?

$ perl -MYAML::Syck -le '$h{bar}=1;$h{bar}=undef;push @{$h{bar}}, qw/a + b c/;print Dump( \%h )' --- bar: - a - b - c

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^6: multiple values for one key in hash
by moritz (Cardinal) on May 13, 2008 at 14:51 UTC
    How would autovivification know that the undef in lvalue context it's autovivifying wasn't the original undef?

    By using a proxy object that acts as undef. Note that you need a reference for autovivification anyway because push @{...} has to modify something that is stored in place of ... anyway.

    I don't know if Perl 5 does it that way, but I think kp6 does.

Re^6: multiple values for one key in hash
by dragonchild (Archbishop) on May 13, 2008 at 14:12 UTC
    huh. My understanding was always that an exists check was done in the background (reflecting my experience with the tied madness that is DBM::Deep), but I've never felt curious enough to explore more deeply.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?