Re: More loops
- From: chas.owens@xxxxxxxxx (Chas Owens)
- Date: Thu, 28 Jun 2007 09:49:29 -0400
On 6/28/07, Jenda Krynicky <Jenda@xxxxxxxxxxx> wrote:
From: "Chas Owens" <chas.owens@xxxxxxxxx>
> On 6/28/07, Jenda Krynicky <Jenda@xxxxxxxxxxx> wrote:
> > From: "Amichai Teumim" <amichai@xxxxxxxxxx>
> 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
===== Jenda@xxxxxxxxxxx === 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;
}
.
- References:
- More loops
- From: Amichai Teumim
- Re: More loops
- From: Jenda Krynicky
- Re: More loops
- From: Chas Owens
- Re: More loops
- From: Jenda Krynicky
- More loops
- Prev by Date: Re: parsing a line
- Next by Date: Re: parsing a line
- Previous by thread: Re: More loops
- Next by thread: parsing a line
- Index(es):
Relevant Pages
|