Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

list/array context mystery

by cajun2019 (Initiate)
on Apr 24, 2001 at 03:29 UTC ( #74912=perlquestion: print w/ replies, xml ) Need Help??
cajun2019 has asked for the wisdom of the Perl Monks concerning the following question:

Apparently (undef)[0] is being interpreted as a null list. In the context of the other statements, why is that? Thanks...
%tmp= (nothing => undef, one => 1); # $tmp{nothing} is undef %tmp= (nothing => (0, undef)[0], one => 1); # $tmp{nothing} == 0 %tmp= (nothing => [undef, 0]->[0], one => 1); # $tmp{nothing} is undef %tmp= (nothing => scalar ((0, undef)[1]), one => 1); # $tmp{nothing} is undef %tmp= (nothing => (undef), one => 1); # $tmp{nothing} is undef %tmp= (nothing => (undef)[0], one => 1); # $tmp{nothing} eq 'one'*** Why not undef? %tmp= (nothing => (undef, 0)[0], one => 1); # $tmp{nothing} eq 'one'*** Why not undef? 1;

Comment on list/array context mystery
Download Code
Replies are listed 'Best First'.
Re: list/array context mystery
by clintp (Curate) on Apr 24, 2001 at 04:19 UTC
    For what it's worth, under 5.6 the last two examples do result in undef.

    Under 5.00503 (the only older version I had laying around) it produces "one". You might want to wander through the changelogs for 5.6 and see what might have fixed this if you're really curious.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (21)
As of 2015-07-29 17:23 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 (266 votes), past polls