We don't have to quibble over semantics, do we?? To me a list is undefined even if it exists but has no items to encompass aor if it has no explicitly named members; to you the very same list is defined to be empty. In any case, I did regard a list devoid of members as being "empty" in my post.

Perl is not matlab or mathematica nor would i wish it to be, even if i were a mathematician I'd appreciate the difference between the return values being 0 or undef, because logically the difference tells me something about the state of operations within the returning subroutine.

Regardless, the sum 0, @list fix is completely fine.

I don't disagree with you or BrowserUk, it's a perfect solution to OP's problem. I just don't see (0, ()) as being the same argument list as (), neither does List::Util::sum() - one is clearly defined, another is not (or in your speak, one is empty, another is not).


perl -e '$,=$",$_=(split/\W/,$^X)[y[eval]]]+--$_],print+just,another,split,hack'er

In reply to Re^3: List::Util::sum() and empty lists... by Firefly258
in thread List::Util::sum() and empty lists... by blazar

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.