Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

by LanX (Bishop)
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]
[marto]: nice to see something like this on a standard home console

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2018-01-18 14:02 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (211 votes). Check out past polls.