Ben said:
WRONG. You mean 'defined'. Whether an element responds to 'exists' or
not depends on whether memory has been allocated to hold that element
yet, which is not generally something you can predict.
In my understanding an array element "exists", when I assigned a
value to it, otherwise not.
my @a;
$a[1] = 4711;
$a[3] = undef;
$a[4] = 4712;
print "exists:\n";
for (my $i = 0; $i < @a; $i++) {
printf " %d %s\n",$i,exists $a[$i]? 'filled': 'empty';
}
print "defined:\n";
for (my $i = 0; $i < @a; $i++) {
printf " %d %s\n",$i,defined $a[$i]? 'filled': 'empty';
}
__END__
exists:
0 empty
1 filled
2 empty
3 filled
4 filled
defined:
0 empty
1 filled
2 empty
3 empty
4 filled
I get what I expect. Where is the problem?