[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Fun w/ autovivification



$ cat j.pl

my $a = {};

# This should fail:
check();

# And doing this has no effect:
my $j = $$a{1};
check();

# But once we do this $$a{1} magically springs into existence...
my $j = $$a{1}{2};
check();


sub check {
   if (exists $$a{1}) {
      print "yup\n";
   } else {
      print "nope\n";
   }
}



$ perl j.pl
nope
nope
yup



More info: http://en.wikipedia.org/wiki/Autovivification

j