Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: wantarray alternative

by tqisjim (Beadle)
on Jul 10, 2013 at 19:04 UTC ( #1043539=note: print w/replies, xml ) Need Help??


in reply to Re: wantarray alternative
in thread wantarray alternative

I did not intend to ask the question How do I use the tertiary operator?. Both these answers rely on the trivial lc operation I used in my example.

To rephrase: What's the most elegant way to modify the default behavior of a subroutine that returns a list of one?

sub lowercase { my @out = map { lc } @_ ; return wantarray ? map { $_ } @out : first { $_ } @out ; }

So my specific question is: How can I move the operation from the first line into the second line to avoid using the place holder out?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043539]
help
Chatterbox?
[Corion]: Congratulations Lady_Aleena ;)
[Lady_Aleena]: Thanks Corion.
[Lady_Aleena]: This is one of my oldest accounts on the web. 8)
[Corion]: Lady_Aleena: Hehe - I think this is also my oldest active account on the web. I have an old university email address but that only gets spam nowadays :)

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-04-26 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (469 votes). Check out past polls.