On Apr 5, 2006, at 11:41 AM, Stewart Leicester wrote:
Actually, those mean different things. Neither autovivifies, which
was
what Doug was seeking to understand.
Both
defined $phash{"D"}[3]
and
exists $phash{"D"}[3]
autovivify $phash{"D"}.
- Bruce
'defined' will autovivify, 'exists' will not.
No, Bruce is right. When used with nested structures, both defined()
and exists() will create the hash element "D", and store a reference
to an anonymous array in it.
But don't take my word for it - just ask Perl. Here's a simple test:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %def_hash;
my %ex_hash;
my $foo = defined($def_hash{'D'}[3]);
print "Using defined():\n", Dumper(\%def_hash), "\n";
my $bar = exists($ex_hash{'D'}[3]);
print "Using exists():\n", Dumper(\%ex_hash), "\n";
This prints:
Using defined():
$VAR1 = {
'D' => []
};
Using exists():
$VAR1 = {
'D' => []
};
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org