Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: More efficient dereferencing of a subroutine return

by LanX (Canon)
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


Comment on Re: More efficient dereferencing of a subroutine return
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2015-07-30 06:22 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