I presume you added the third case to show that the value of $_ has no bearing on the first two cases. Here's that fact illustrated a little better:

>perl -MO=Deparse -wle "print defined +() ? 1 : 0" print defined(()) ? 1 : 0; >perl -MO=Deparse -wle "$_ = 1; print defined +() ? 1 : 0" $_ = 1; print defined(()) ? 1 : 0; >perl -MO=Deparse -wle "$_ = 1; print defined () ? 1 : 0" $_ = 1; print defined $_ ? 1 : 0;

Update: Why are you checking for defined? define accepts a scalar, not specifically a boolean. False is defined, so your tests should all print 1 if you were truly examining lists in boolean contexts. (False is 0 in numerical context and "" in string context.) To check the value of a list in a boolean context, simply run the following:

>perl -wle "print(()?'True':'False');" False

I think your question is invalid. Just like there's no such thing as a list in scalar context, I'm guessing that there is no such thing as a list in a boolean context. It's up to the functions returning lists to provide the value.


In reply to Re: An empty list in boolean context? by ikegami
in thread An empty list in boolean context? by BUU

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.