In the following code, the second call to use_hash fails:
use strict;
use warnings;
$|=1;
sub empty_list {
@{ [] }
}
sub use_hash {
my (%h) = @_;
print(join(',',keys %h),"\n");
}
use_hash(foo1 => undef, bar1 => 5);
print "not defined\n" unless defined ((empty_list)[0]);
use_hash(foo2 => (empty_list)[0], bar2 => 5);
The ouput of the program is as follows:
bar1,foo1
not defined
Odd number of elements in hash assignment at C:\tmp\emptylist_a.pl lin
+e 12.
foo2,5
We see that the first
use_hash works. We also see that (not surprising) an empty list indexed by [0] yields undef. I would have expected the 2nd call to
use_hash being the same as the first: Instead of passing
undef<c> explicitly to key <c>foo2, I "generate" it by taking the first element of an empty list. However, the latter does not work.
--
Ronald Fischer <ynnor@mm.st>