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.


In reply to Re^3: Can't understand function returning undefs by ikegami
in thread Can't understand function returning undefs by rg0now

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.