Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Empty List miracle (2)

by Sandy (Curate)
on Apr 29, 2010 at 14:20 UTC ( #837549=note: print w/ replies, xml ) Need Help??


in reply to Empty List miracle (2)

If you compare the output of your empty_list routine in scalar and list context:

sub empty_list { return @{ [] } } my @y=(empty_list())[0]; my $x = (empty_list())[0]; use Data::Dumper;print Dumper \$x,\@y;
You will see that @y is an empty array, and $x is undef.

think of the difference between using $x and @y in your hash declaration:

my @y=(empty_list())[0]; # @y = (); my $x = (empty_list())[0]; # $x = undef; my %x = (foo=>$x); my %xx = (foo=>@y);
So, to use your function in your hash declaration, you need to force scalar context.
my %x=(foo=>scalar((empty_list1())[0]));


Comment on Re: Empty List miracle (2)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://837549]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2015-07-30 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls