Re: More loops



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

.



Relevant Pages