SPUG: English-speak about Perl-speak "for" loops

Jacinta Richardson jarich at perltraining.com.au
Wed Sep 20 19:22:10 PDT 2006


BenRifkah Bergsten-Buret wrote:

> This:
>     for (my $i = 0; $i < @array - 1; $i++)
> 
> becomes this:
>     for my $i (0 .. $#array)
> 
> regardless of whether you intended to use 'array' as the name of two 
> different variables or had a typo.

Actually, I think you'll find that the first example up there is the
same as :

	for my $i (0 .. ($#array - 1) )

because you've used < *and* @array-1.  Had you written:

	for (my $i = 0; $i <= @array - 1; $i++)

or

	for (my $i = 0; $i < @array; $i++ )

then they would have been equivalent to your second example.

All the best,

	Jacinta


More information about the spug-list mailing list