E.g., does perl avoid copying of data in the following cases?
No. The array is copied in both those cases.
There are two ways of avoiding that:
sub large_array_ref { my $large_array_ref = []; ...populate @$large_array_ref... return $large_array_ref; } my $c = large_array_ref(); $c->[ ... ];
sub large_array_ref { my $large_array_ref = shift; ...populate @$large_array_ref... return; } large_array_ref( \my @c ); $c[ ... ];
With a suitably chosen name for the sub, the latter looks less awkward:
populateThingArray( \my @c ); $c[ ... ];
In reply to Re: returning large arrays from functions
by BrowserUk
in thread returning large arrays from functions
by perl5ever
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |