in reply to autovivication gonna make me lose my mind

If you're dereferencing an element as an lvalue (i.e., in a kind of assignment), it will autovivify. If you're dereferencing otherwise, it will fail.

For example:

$ perl -le 'use strict;my %h;push @{$h{first}}, "hello";print $h{first +}' ARRAY(0x8153d78) $ perl -e 'use strict;my %h;print @{$h{first}}, "hello";' Can't use an undefined value as an ARRAY reference at -e line 1.

Replies are listed 'Best First'.
Re^2: autovivication gonna make me lose my mind
by dreadpiratepeter (Priest) on Sep 16, 2008 at 16:06 UTC
    A ha, that's my disconnect. I got the error for an rvalue at some point and drew the wrong conclusion (I generalized it to lvalues too). So I have cargo-culted myself for the last few years. Time to simplify some code.
    Thank you so much for dispelling my confusion


    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
Re^2: autovivication gonna make me lose my mind
by ig (Vicar) on Nov 04, 2008 at 14:06 UTC