On 7/31/07, Jeff Pang <[EMAIL PROTECTED]> wrote:
>
> --- Chas Owens <[EMAIL PROTECTED]> wrote:
> >
> > oops, the map should be
> >
> > print map { join(",", ($_) x $i++),"\n" } @a;
> >
>
> Also using for loop is may better since many ppl on
> this list said map would consume too much memory if
> the input array is large enough.
>
> print join(",", ($_) x ++$i),"\n" for @a;

Whereas it is true that map uses need more memory than a for loop in
Perl 5*, this is generally not a problem with arrays that are not tied
objects since arrays should be fairly small (under 10,000 items).  If
your arrays are very large you probably should not be using arrays in
the first place.  In this specific case the number of items in the
array is guaranteed to be between 0 and 5.

* Perl 6 is getting at least some lazy evaluation, so it may not have
this problem.

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


Reply via email to