Hi,

I think it is good to have foreach and for loop
even tough they are the same
if you are searching in a file you can almost make a sentence
foreach $line(@infile) #<-- to me this is more readable
than
for $line(@infile)
But for loop, I use it only for numbers
for(1..53) or for( $i=0;$i<50;$i++);
it is also close to c++ so the transition from one language to another is
tiny bit easier.
This is my little point of view.

Anthony



"David" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Peter Fleck wrote:
>
> > I just stumbled upon this in some perl I'm working on:
> >
> > for $arrayref (@datedbi) {
> >     #do stuff
> > }
> >
> > It didn't look right and sure enough, it should be 'foreach'.
> >
> > But it worked fine and that's my question - why is this working?
> >
> > @datedbi's elements are references to lists and they all seem to be
> > getting processed the way I want whether I use 'for' or 'foreach' in
> > the code.
>
> Perl internally compiles 'for' into 'foreach' for you:
>
> [panda]$ perl -MO=Deparse -e 'for $i (1..4){;}'
> foreach $i (1 .. 4) {
>     ();
> }
> -e syntax OK
> [panda]$
>
> they are exactly the same.
>
> david



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to