Okay, I'll concede this one:

$ perl -wMstrict -le 'if((2,1,0)) {print"true"}else{print"false"}' Useless use of a constant (2) in void context at -e line 1. false

Although that's the comma operator operating in scalar context, (2,1,0) might be what people might think of when they think "list". But:

$ perl -wMstrict -le 'if(()=(2,1,0)) {print"true"}else{print"false"}' true

although admittedly that's the result of a list assignment in scalar context.

In this thread we're talking about return, and I haven't yet found a way for a return 0; in some kind of list context to be evaluated as false:

$ perl -wMstrict -le 'sub foo { print wantarray?"list":"scalar"; return (0); }; if(foo) {print "true"} else {print "false"} ' scalar false $ perl -wMstrict -le 'sub foo { print wantarray?"list":"scalar"; return (0); }; if(()=foo) {print "true"} else {print "false"} ' list true $ perl -wMstrict -le 'sub foo { print wantarray?"list":"scalar"; return (0); }; my @x=foo;if(@x) {print "true"} else {print "false"}' list true

Although those last two are respectively, a list assignment and an array, not exactly a list.

So in the above examples, it's never really the lists which are directly in boolean context, so I kind of get what you are saying. But then again, the way I see it conceptually, in Perl, when you evaluate lists/arrays in a scalar context they evaluate to one of two things: their last element (although that one is usually the result of the comma operator in scalar context), or a count of their elements - and at least in my mind that's the underlying principle why a list with >0 elements is always "true". I haven't yet been able to come up with a counterexample where a list with at least one element somehow fiddled into a boolean context evaluates to false; if you've got one, I don't mind being proven wrong.

For my final argument, perlsyn, emphasis mine:

The number 0, the strings '0' and "", the empty list (), and undef are all false in a boolean context. All other values are true.

In reply to Re^4: What could make "()" a good value for boolean false? by Anonymous Monk
in thread What could make "()" a good value for boolean false? by morgon

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.