Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by LanX (Canon)
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! :)

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)


Comment on Re: There's scalar(), but no list(). Perl could need one for rare but reasonable use
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1089895]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-07-24 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (159 votes), past polls