On 6/28/07, Jenda Krynicky <[EMAIL PROTECTED]> wrote:
From: "Chas Owens" <[EMAIL PROTECTED]>
> On 6/28/07, Jenda Krynicky <[EMAIL PROTECTED]> wrote:
> > From: "Amichai Teumim" <[EMAIL PROTECTED]>
> snip
> > > foreach $elem (@array){
> > > print "$elem\n";
> > > }
> >
> > This can be simplified to
> >
> > print join("\n", @array), "\n";
> snip
>
> or (since this is Perl and TIMTOWTDI)
>
> print map { "$_\n" } @array;
or
print "$_\n" for @array;
or (and all beginners should close their eyes since I'm going dirty
now)
{ local $" = "\n";
print "@array\n";
}
or
{ local $, = "\n"; local $\ = "\n";
print @array;
}
or
{ local $\ = "\n";
print for @array;
}
Hello Tim, how's missis Toady? ;-)
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
Well, if we are going to be silly, how about
s/$/\n/s for @array;
print @array;
s/\n$//s for @array;
or
printf join('',("%s\n") x @array), @array;
or
{ local $" = '';
printf qq/@{[("%s\n") x @array]}/, @array;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/