Re: More loops



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;
}
.



Relevant Pages

  • Re: How to list the statement of all var ?
    ... > of an object when the question was about `var' statements? ... And as soon as i will test it for this particular host ... to use an Object object instead of an Array object. ...
    (comp.lang.javascript)
  • Re: Weird regexp problem
    ... What's in @array here? ... I'm still not clear what makes you think this is a regexp problem. ... MySQL executes the exact query as it receives from Perl. ...
    (comp.lang.perl.misc)
  • Re: Warning on assigning a function-returning-a-pointer-to-arrays
    ... reminder that it's a pointer and not merely a locally declared array ... That would indicate a bug in the compiler, ... int main{ ...
    (comp.lang.c)
  • Re: Pleac: Programming Language Examples Alike Cookbook
    ... decided to send the youngest, Josh, to buy some beer. ... it's not intended to be an array unset. ...
    (comp.lang.tcl)
  • Idle curiosity (ieee bitorder)
    ... >> Where this becomes a problem is the byte array is LITTLE ENDIAN. ... The GCM specification has no concept beyond bit sequences. ... Without naming bits in some way and carefully specifying what we mean by ...
    (sci.crypt)