in reply to Re^2: Hashing it out: defined? exists?
in thread Hashing it out: defined? exists?
None of them will.
{ my %h; 1 if exists $h{key}; print("exists: ", (%h ? "auto-vivi" : "empty"), "\n"); } { my %h; 1 if defined $h{key}; print("defined: ", (%h ? "auto-vivi" : "empty"), "\n"); } { my %h; 1 if $h{key}; print("true: ", (%h ? "auto-vivi" : "empty"), "\n"); } __END__ exists: empty defined: empty true: empty
The following are the only forms of auto-vivification that come to mind:
# If $h{$i} and $a[$i] are not defined, $h{$i}{$j} # Creates a hash and stores a ref to it in $h{$i}. $h{$i}[$j] # Creates an array and stores a ref to it in $h{$i}. $a[$i]{$j} # Creates a hash and stores a ref to it in $a[$i]. $a[$i][$j] # Creates an array and stores a ref to it in $a[$i].
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Hashing it out: defined? exists?
by Nkuvu (Priest) on Sep 02, 2005 at 20:19 UTC | |
by ikegami (Patriarch) on Sep 02, 2005 at 20:25 UTC |