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

BenRifkah Bergsten-Buret benb at speakeasy.net
Mon Sep 18 10:47:36 PDT 2006


Ingy dot Net wrote:
> How would you better express:
>     for (my $i = 0; $i < @array - 1; $i++) {
>         $array->[$i + 1] += $array[$i];
>     }
>
> The C style loop has its place in Perl.
>   

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.

-- Ben


More information about the spug-list mailing list