Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: More efficient dereferencing of a subroutine return

by LanX (Chancellor)
on Feb 18, 2013 at 02:40 UTC ( #1019264=note: print w/ replies, xml ) Need Help??

in reply to More efficient dereferencing of a subroutine return

Are you aware that Perl has list-context?

my @ARRAY=subroutine(); sub subroutine { my @array=("one", "two"," three"); return @array; }

If you still need to return an array-ref in other cases just check wantarray in a condition to see if a scalar is expected.

return wantarray ? @array : \@array;

Cheers Rolf

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019264]
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: (12)
As of 2016-07-29 06:47 GMT
Find Nodes?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?

    Results (260 votes). Check out past polls.