Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: There's scalar(), but no list(). Perl could need one for rare but reasonable use

by LanX (Chancellor)
on Jun 14, 2014 at 14:48 UTC ( #1089895=note: print w/replies, xml ) Need Help??

in reply to There's scalar(), but no list(). Perl could need one for rare but reasonable use

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! :)


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.


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)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1089895]
and monks are getting baked in the sun...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-08-17 22:36 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (294 votes). Check out past polls.