Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: wantarray alternative

by kcott (Abbot)
on Jul 11, 2013 at 11:30 UTC ( #1043697=note: print w/ replies, xml ) Need Help??


in reply to wantarray alternative

G'day tqisjim,

I changed this a few times as you posted updates. Anyway, here lowercase() contains one line, doesn't use temporary arrays, doesn't require other functions and returns the values you show in "Three conditions:" (using the same lowercase(...) calls).

$ perl -Mstrict -Mwarnings -E ' sub lowercase { return (map { lc } @_)[wantarray ? (0 .. $#_) : 0]; } my (@me, $me); @me = lowercase( qw( TQIS Jim ) ) ; ## returns qw( tqis jim ) say "@me"; $me = lowercase( q{Jim} ) ; ## returns q{jim} say "$me"; @me = lowercase( qw( Jim ) ) ; ## returns qw( jim ) say "@me"; ' tqis jim jim jim

Update: It would appear that, amidst all the various updates, I missed Re: wantarray alternative (Context propagation) by ++LanX which is a virtually identical solution but with a somewhat cleverer idiom:

(map { lc } @_)[0 .. wantarray * $#_]

-- Ken


Comment on Re: wantarray alternative
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2015-07-30 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls