The @_ array in a sub is like what happens in a foreach loop where modifying $_ during an iteration is modifying the actual element itself. This is accomplished without copying the array (in current versions of Perl), but with some internal stuff that creates aliases.
Something similar happens in a sub. Each element in the @_ array is an alias to the actual variable - so you can modify it and change the variable it aliases. According to belg4mit in the CB, copying doesn't actually happen until you make an assignment such as my $variable = $_[0];. The thing is knexus didn't do that - they made an assignment to a reference to the alias. I do not know if that makes a copy or not (Benchmark would be one way to find out for sure).
In any case I stand by my original post for a more conventional way of doing it even if my rationale was flawed.
Cheers - L~R
In reply to Re: Re: Re: Memory Use and/or efficiency passing scalars to subs
by Limbic~Region
in thread Memory Use and/or efficiency passing scalars to subs
by knexus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |