Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Trouble getting size of list returned from sub

by ColonelPanic (Friar)
on Nov 26, 2012 at 14:43 UTC ( #1005678=note: print w/ replies, xml ) Need Help??


in reply to Trouble getting size of list returned from sub

Yet another solution that uses less memory than a temporary array:

sub get_size {scalar @_} my $size = get_size(big_list());

Using the list returned from the sub as the args for another subroutine call is a sneaky way to get an array without actually making a copy.

It makes for pretty intuitive code, too. And it probably isn't limited to recent Perl versions, as the map solution is.



When's the last time you used duct tape on a duct? --Larry Wall


Comment on Re: Trouble getting size of list returned from sub
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2014-09-20 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (163 votes), past polls