From: Rob Dixon <[EMAIL PROTECTED]>
> Charlie Farinella wrote:
> >
> > I have a string of text that I want to split on the tabs:
> > 
> > while (<INFILE>) {
> >     my @array = split(/\t/, $_);
> > 
> > ...manipulate them a little, and print them back out like so:
> > 
> >     print "$array[0],$array[1],$array[2]"; etc.
> > }
> > 
> > I normally just print them as above, but I'm thinking there must be a 
> > better way.
> > What's the most efficient way to print them all out? 
> 
> Just
> 
>   print "@array\n";
> 
> will output the elements separated with spaces by default. To change the
> separator to a comma you can write
> 
>   local $" = ',';
>   print "@array\n";

print join(',', @array), "\n";

is much cleaner and safer. Leave $" alone.

Jenda
===== [EMAIL PROTECTED] === 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


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to