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

Re^3: wantarray alternative

by LanX (Abbot)
on Jul 10, 2013 at 21:29 UTC ( #1043570=note: print w/ replies, xml ) Need Help??


in reply to Re^2: wantarray alternative
in thread wantarray alternative

> If the explanation is that map is being called in scalar context, then the following is unexpected:

no! whatever comes after return is executed in the context of the sub's call.

so in this case¹ $name = scalar @out

It's true many people expect a LIST to be returned but thats generally wrong in scalar context.

A helper routine  sub listify { (@_)[0..$#_] } might help to assure this "expected" behaviour, whenever you need to return a LIST².

Cheers Rolf

( addicted to the Perl Programming Language)

PS: please read the thread I linked before asking more questions.

¹) which isn't the code from the post I replied to, where a map-statement is returned

UPDATE

> Clever, but not elegant.

Larry will be so devastated to hear this ... :´(

UPDATE

²) FWIW

DB<112> sub listify { (@_)[0..$#_] } DB<113> sub tst { listify map{lc} @_ } DB<114> $s =tst("A".."D") => "d" DB<115> @l =tst("A".."D") => ("a", "b", "c", "d")


Comment on Re^3: wantarray alternative
Select or Download Code
Re^4: wantarray alternative
by tqisjim (Beadle) on Jul 10, 2013 at 22:28 UTC

    Larry will be so devastated to hear this ... :´(

    Nuff said

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-04-20 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (488 votes), past polls