in reply to Re: restricting values to a nested datastructure
in thread restricting values to a nested datastructure

I installed and tested this autovivification critter on my ActiveState Windows machine. Looks like it works just fine. Although I am a bit puzzled why I didn't need a "use Autovivification;" statement. However this does appear to work and in a lexical context as described in the docs.
#!/usr/bin/perl -w use strict; use Data::Dumper; my %a; { no autovivification 'exists'; if (exists ( $a{'abd'}->[0] ) ) { print "yes \n"; } } print Dumper \%a; if (exists ( $a{'abd'}->[0] ) ) { print "yes \n"; } print Dumper \%a; __END__ $VAR1 = {}; $VAR1 = { 'abd' => [] };

Replies are listed 'Best First'.
Re^3: restricting values to a nested datastructure
by tobyink (Canon) on Dec 14, 2011 at 13:17 UTC

    Perl's no keyword autoloads the module for you.

    use Foo is an abbreviation for:

    BEGIN { require Foo; } Foo->import;

    The counterpart no Foo is an abbreviation for:

    BEGIN { require Foo; } Foo->unimport;

    Because import and unimport are just regular old subs, this means that modules can do their interesting stuff with no instead of use. It's a cute trick, though can confuse people.