in reply to Re: exists on hash autovivifies right?
in thread exists on hash autovivifies right?

If you need to test for existence without autovivification, you'll have to code up a test that goes something like this:
sub my_exists { my $struct = shift; while (@_) { my $key = shift(@_); return false unless exists $hash->{$key}; $hash = $hash->{$key}; } 1; } my $x = {}; if (my_exists($x, 'a', 'c')) { print "c exists\n"; } else { print "c doesn't exist\n"; } print Dumper($x);

Replies are listed 'Best First'.
Re^3: exists on hash autovivifies right?
by lodin (Hermit) on Jun 29, 2008 at 09:55 UTC
      nice modu;es. thanks.
Re^3: exists on hash autovivifies right?
by Anonymous Monk on Jun 29, 2008 at 21:03 UTC
    nice solution. thanks.