[greg@webzavod.ru - Fri Feb 8 02:22:13 2002]:
Show quoted text> There may be a benefit when you pass _reference_ to large chunk of data from
> one sub of your application to another and finally print it instead of
> passing data value.
Well, the way you pass data around in your application doesn't really have anything to do with how you pass it to print() at the end.
Also, I've run a benchmark, and it indicates that using references just for their own sake actually slows things down:
--------------------------------------------------------------------
[junior:~/bin/test] ken% cat bench.pl
#!/usr/bin/perl
use Benchmark;
open my($fh), "> /dev/null" or die $!;
sub print_regular { print $fh @_ }
sub print_deref { print $fh map {ref() ? $$_ : $_} @_ }
$long_string = "x" x 100_000;
$long_string2 = "y" x 100_000;
timethese(500_000, {
'print_regular' => 'print_regular($x, $y)',
'print_deref' => 'print_deref(\$x, \$y)',
});
[junior:~/bin/test] ken% perl bench.pl
Benchmark: timing 500000 iterations of print_deref, print_regular...
print_deref: 6 wallclock secs ( 5.34 usr + 0.00 sys = 5.34 CPU) @ 93632.96/s (n=500000)
print_regular: 1 wallclock secs ( 1.73 usr + 0.00 sys = 1.73 CPU) @ 289017.34/s (n=500000)