Marc Perry wrote:
Hi,
Hello,
I noticed that most beginner texts will introduce and use print like this:
print $moose, $squirrel, $boris, "\n";
However, when I review code from CPAN, I often (typically) see:
print $bullwinkle . $rocky . $natasha . "\n";
As I recall, print is a list operator (and therefore the comma syntax is
used to separate items in a list), but is catenation somehow faster/more
memory efficient?
AFAIK there is no practical difference in efficiency.
The first is short for:
print join( $,, $moose, $squirrel, $boris, "\n" );
Where print() creates the string it outputs by joining the list elements
using the $, variable.
Also of note is that each element is in LIST context whereas in the
second example each element is in SCALAR context. This _could_ make a
difference, for example:
print "start ", localtime, " end\n";
Versus:
print "start " . localtime . " end\n";
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/