in reply to Empty List miracle (2)
If you compare the output of your empty_list routine in scalar and list context:
You will see that @y is an empty array, and $x is undef.sub empty_list { return @{ [] } } my @y=(empty_list())[0]; my $x = (empty_list())[0]; use Data::Dumper;print Dumper \$x,\@y;
think of the difference between using $x and @y in your hash declaration:
So, to use your function in your hash declaration, you need to force scalar context.my @y=(empty_list())[0]; # @y = (); my $x = (empty_list())[0]; # $x = undef; my %x = (foo=>$x); my %xx = (foo=>@y);
my %x=(foo=>scalar((empty_list1())[0]));
|
---|
In Section
Seekers of Perl Wisdom