in reply to Trouble getting size of list returned from sub
Here is a solution that potentially uses less memory:
When's the last time you used duct tape on a duct? --Larry Wall
my $size = scalar map {1} big_list;
Explanation: All of the other options involve copying the return arguments into an array behind the scenes. This does not, instead creating an array with the same number of elements, but containing the value "1" for each element. This will use less memory if the the sub is returning a list of large items (such as long strings).
This would be worth trying if you have problems with high memory usage.
(To test this, see the sample code with memory usage test above)
When's the last time you used duct tape on a duct? --Larry Wall
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Trouble getting size of list returned from sub
by Anonymous Monk on Nov 26, 2012 at 11:17 UTC | |
by ColonelPanic (Friar) on Nov 26, 2012 at 12:25 UTC | |
by Anonymous Monk on Nov 26, 2012 at 15:24 UTC | |
by ColonelPanic (Friar) on Nov 26, 2012 at 15:40 UTC |
In Section
Seekers of Perl Wisdom