Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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:

  • ($a)=call() (great for iterators) or
  • $a=[call()] (gimme the reference)
  • simply die (never meant to return scalar)

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-23 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found