Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: wantarray alternative

by davido (Archbishop)
on Jul 10, 2013 at 19:59 UTC ( #1043546=note: print w/replies, xml ) Need Help??


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

return @out == 1 && ! wantarray ? $out[0] : @out;

So if @out has a single element, return '1'. If it contains zero or 2, or more elements, then if "wantarray", return @out, otherwise return the first element.

I can't imagine using that once, let alone thousands of times. ;)

Update: Woops, "&&" is higher on the precedence table than "?:" in any language I know of. My mistake.


Dave

Replies are listed 'Best First'.
Re^4: wantarray alternative
by tqisjim (Beadle) on Jul 10, 2013 at 20:35 UTC
    Oops. Thanks for catching that :)
    return ( @out == 1 && ! wantarray ) ? $out[0] : @out;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043546]
help
Chatterbox?
[Corion]: marto: You mean "Sane Dots Dramatic Reading of ITIL" ? ;)
[marto]: Sane Dots, chapter 13: ITIL never work :P
[marto]: sorry, bad pun of it'll :P
[Corion]: :-D
[Corion]: I think that ITIL is mostly to prevent people from doing harm to a system that basically runs unattended :)
[Corion]: Maybe you could reduce ITIL to a computer network, a man and a dog. The network runs the computations. The man is there to feed the dog. The dog is there to prevent the man from accessing the computers.
[marto]: from experience of this side of the fence, it's all about proving to people that you are ITIL compliant, then the client ignores logical processes anyway :P

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2017-01-24 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (203 votes). Check out past polls.