Re: Variable scope behavior in foreach loop

2001-06-07 Thread Peter Scott
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'r

Re: Variable scope behavior in foreach loop

2001-06-07 Thread Jeff 'japhy' Pinyan
On Jun 7, Paul said: >--- "Robin Lavallee (LMC)" <[EMAIL PROTECTED]> wrote: >> Then can someone explains why the following code: >> >> #---Begin Code--- >> use strict; >> my $par="50"; >> print "$par\n"; >> >> my @arr = ('first', 'second', 'third'); >> foreach $par (@arr) >> { >> print "$p

Re: Variable scope behavior in foreach loop

2001-06-07 Thread Paul
--- "Robin Lavallee (LMC)" <[EMAIL PROTECTED]> wrote: > Then can someone explains why the following code: > > #---Begin Code--- > use strict; > my $par="50"; > print "$par\n"; > > my @arr = ('first', 'second', 'third'); > foreach $par (@arr) > { > print "$par\n"; > } > print "$par\n"; > #

Re: Variable scope behavior in foreach loop

2001-06-07 Thread Paul
--- "Robin Lavallee (LMC)" <[EMAIL PROTECTED]> wrote: > > Hi, > > 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) { ... } > > Because it does not reallocate memory each