At 01:08 PM 6/7/01 -0400, Robin Lavallee (LMC) wrote:
>         I have a small conceptual problem. I have been
>told that doing:
>
>my $item;
>foreach $item (@arr) { ... }
>
>is more efficient than:
>foreach my $item (@arr) { ... }

Even if it is, this is the wrong thing to optimize for.  If you're creating 
something that's so close to its performance requirements margins that you 
need this kind of benefit, you should be implementing it in another 
language or looking for savings elsewhere.

Optimize first for people, second for hardware.  (I can't resist pointing 
out that I said that in my book :-)  In this case, creating a variable 
$item whose scope extends beyond what is necessary impacts maintainability 
to some extent.  Do what makes you happy and worry about performance only 
when you have evidence that you need to.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com

Reply via email to