in reply to Re^2: Whats quicker - passing along as variable to sub, or global var?
in thread Whats quicker - passing along as variable to sub, or global var?
Not sure what you mean?
I meant exactly what I wrote: Passing a string to a function doesn't make a copy. Assigning it to a separate variable does. So
sub f { print $_[0]; }
avoids the copy, whereas
sub f { my $x = $_[0]; # copy created here print $x; }
creates one.
Since it's quite ugly to use $_[NUMBER] all the time, I suggested references instead.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Whats quicker - passing along as variable to sub, or global var?
by ultranerds (Hermit) on Apr 08, 2011 at 13:50 UTC | |
by bart (Canon) on Apr 08, 2011 at 21:33 UTC |