Thanks for the clarification.

The way context is propagated to the return statement (resp. the last statement) of a sub is indeed a problem.

( its too surprising how return 1..3 behaves and suddenly transforms into a flip flop)

That's why subs were remodeled in Perl 6 and I'd really appreciate a similar feature or pragma switch in Perl 5.

Regarding your list() routine, I think it solves the wrong problem . The behavior of comma separated lists comes from the "scalar comma operator" and is rarely useful.

The IMHO "most normal behavior" is to return a count, like arrays do. This fits perfectly into boolean context! That's why I occasionally wrap my values into a @{[...]} construct.

But that's too short to justify an own built-in function.

Maybe something like arr() could at least add some more readability.

YMMV! :)

update

To complete the picture, I was also in situations where I would have preferred $a=call() to act like:

Tastes differ, IMHO its rather a question of clear notation.

update

And wantarray is not only a misnomer, but too difficult handle in 3 contexts. Damien published a module handling this which should better be XSed and Core.

Cheers Rolf

(addicted to the Perl Programming Language)


In reply to Re: There's scalar(), but no list(). Perl could need one for rare but reasonable use by LanX
in thread There's scalar(), but no list(). Perl could need one for rare but reasonable use by flowdy

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.