in reply to recursive exists in perl

no autovivification; if (exists($h{A}{B}{C})) { }

autovivification

Replies are listed 'Best First'.
Re^2: recursive exists in perl
by gsiems (Deacon) on Dec 10, 2010 at 02:49 UTC

    Is that really the case? For example, while the following doesn't autovivify $h{A}{B}{C} it does autovivify $h{A}{B}.

    use Data::Dumper; my %h; if ( exists( $h{A}{B}{C} ) ) { print "Hi mom!\n"; } print Dumper \%h;

    $VAR1 = {
              'A' => {
                       'B' => {}
                     }
            };
    
      use Data::Dumper; my %h; no autovivification; if ( exists( $h{A}{B}{C} ) ) { print "Hi mom!\n"; } print Dumper \%h; __END__ $VAR1 = {};

        Ah! Here I was thinking that "no autovivification" was commentary.

        cpanp -i autovivification

        Runs script again... sweet.

        Thank you kind Anonymous for enlightening this humble monk.