in reply to Re: Autovivification and soft refs
in thread Autovivification and soft refs

Just add a bit of info on top of what Abigail-II said. If you my %stopper, it will stop the autovivification:

use Data::Dumper; my %stopper; $x = 'stopper'; exists $x->{'y'}->{'z'}; print Dumper $x; print Dumper \%stopper;

Which prints:

$VAR1 = 'stopper'; $VAR1 = {};

Comment out that my %stopper line, you will see the autovivification:

$VAR1 = 'stopper'; $VAR1 = { 'y' => {} };

Replies are listed 'Best First'.
Re: Autovivification and soft refs
by Abigail-II (Bishop) on Jan 22, 2004 at 09:35 UTC
    If you my %stopper, it will stop the autovivification:
    Well, that would be strange. Very, very strange. Do you think that happens because there's an explicite check in perl that says "hmmm, we are doing autovivification of a secondary key in the hash, but the parent hash is a lexical, so let's not do it", or that you've hit a strange bug?

    Or could it be that autovivification is happening? And you are just giving the wrong argument to Dumper? Try giving \%{"stopper"} as argument to Dumper.

    Abigail

Re: Re: Re: Autovivification and soft refs
by thelenm (Vicar) on Jan 22, 2004 at 05:03 UTC

    Now that's interesting. Your post inspired me to dig a little deeper... it looks like the autovivification is still happening, but not on the lexical %stopper. Instead the global %::stopper is affected. Which makes sense, I suppose, because %::stopper is what was being affected in Abigail's original snippet, and with no lexical on scope, %stopper (i.e. the symbolic reference) was really referring to %::stopper. Very interesting, I certainly learned something. Thanks for pointing that out!

    use Data::Dumper; my %stopper; $x = 'stopper'; exists $x->{'y'}->{'z'}; print Dumper $x; print Dumper \%stopper; print Dumper \%::stopper;

    -- Mike

    --
    XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
    -- grantm, perldoc XML::Simpler