On Mon, Mar 21, 2011 at 01:46, Mike McClain <m.d.mccl...@cox.net> wrote:
snip
>> > my @report = map
>> > "$_->{cell}\t$_->{sect}\t$_->{carr}\t$_->{chan}\t$_->{dist}\n" , @sorted;
>> > print @report ;
>>
>> This map will consume a lot of memory, better do it using a foreach loop.
>
> In what way will the use of map here use any more memory than a foreach loop?
snip

The problem is that map returns a list.  That list will exist in
memory as you copy it to @report.  Just before the assignment is
finished, you will be using twice the amount of memory you expect.
Perl doesn't tend to return memory to the system, so, even though no
variable is using it, the memory used to hold the list will still be
held by perl.  Happily, perl will reuse the memory, so, as long as it
isn't huge, it normally isn't a big deal.



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to