Perl does not employ a copy-on-write mechanism. As such, assigning a one array to another (as in the second example) involves copying the elements, not just copying a reference to the elements.
In the first example, you're not even assigning an array to an array. You're getting a list of the elements in the array, then you're assigning that list to another array. You might end up copying each element twice! I know there's at least one optimisation in place, but there's no escaping copying each element at least once for the reason I gave above.
In reply to Re: returning large arrays from functions
by ikegami
in thread returning large arrays from functions
by perl5ever
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |