On Tuesday 22 Dec 2009 15:01:47 Jenda Krynicky wrote:
> From: Marc Perry <marcperrys...@gmail.com>
> 
> > 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?
> 
> Compared with the price of the IO operation the concatenation versus
> passing several values is irrelevant. I do not dare to guess which
> one is more efficient in what circumstances, but I don't think the
> difference matters.
> 

I should note that there's a small difference in behaviour. Reading from 
http://perldoc.perl.org/perlvar.html :

<<<<<<<<<<
#

# IO::Handle->output_field_separator EXPR
# $OUTPUT_FIELD_SEPARATOR
# $OFS
# $,

The output field separator for the print operator. If defined, this value is 
printed between each of print's arguments. Default is undef. (Mnemonic: what 
is printed when there is a "," in your print statement.)

>>>>>>>>>>

Of course, setting it to anything but the default is a sure fire way to break 
practically most production code out there , and "Perl Best Practices" 
recommends against setting it. But it may be useful in one-liners / small 
scripts / golfs / obfuscations / etc.

Regards,

        Shlomi Fish

> Jenda
> ===== je...@krynicky.cz === http://Jenda.Krynicky.cz =====
> When it comes to wine, women and song, wizards are allowed
> to get drunk and croon as much as they like.
>       -- Terry Pratchett in Sourcery
> 

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Why I Love Perl - http://shlom.in/joy-of-perl

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to