in reply to Re^2: Can't understand function returning undefs
in thread Can't understand function returning undefs

This is closely related to the concept of the default input operator

What are you talking about???

And the rest of the post is no better. So many errors!

sub a{ return 1, 2, 3 } a();

This evaluates what a() returns, in scalar context. $_ gets the last value returned by a(). In this case, $_ is 3, or True if evaluated in Boolean context. If you tested $x = a(), you'd get the same True result, with $x equal to 3.

sub a{ return 1, 2, 0 }  a();

$_ gets the last value returned by a(), as before. In this case, $_ is 0 in scalar context, or False in Boolean context!

@a = (undef, undef); @a;

This array is evaluated in scalar context because we haven't done anything to force list context. An array, evaluated in scalar context, is always the number of elements it contains.

sub a{ return 1, 2, 0 } ($x,$y) = a();

We're still evaluating what a() returns, but here we've forced list context. That means that $_ is assigned the number of elements in the list returned, not the elements. It doesn't matter what a() returns -- if it returns one or more elements, $_ will be set to non-zero, or True in Boolean context.

sub a{ return 1, 2, 0 }  @arr = a();

Exactly the same as above.

(undef, undef);

An array is a container for a list. This is NOT an array, and we haven't done anything to force list context, so we have a list of scalars evaluated in scalar context. $_ is set to the last element, which is undef -- or False in Boolean context.

sub a { return undef, undef } ($x, $y) = a(); if(not $x && not $y) { print "False\n" }

I think this is closer to what you're looking for. Whenever you don't specifically lay out the condition you are testing, you are probably testing $_.

No, it's not what he wants.

I hope this helps.

Pure harm. Good thing the formatting makes it unreadable.