in reply to Re^3: C-style for loop
in thread C-style for loop
I gave you a reason for preferring the Perl style for loop in general - fewer parts to go wrong. Eliminating a variable is not generally the important difference between two different for loop usages. Indeed:
for my $index (0 .. $#array) { ... }
Is generally a much better solution than:
for (my $index = 0; $index < $#array; ++$index) { ... }
because the range of the Perl loop is much easier to see and harder to get wrong.
In general we can say what sort of for loop is better - Perl for loops. '"C-style" is bad because of useless $i variable' is not the reason however.
Perl reduces RSI - it saves typing
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: C-style for loop
by ccn (Vicar) on Nov 15, 2008 at 22:01 UTC | |
by GrandFather (Saint) on Nov 15, 2008 at 23:08 UTC | |
by ikegami (Patriarch) on Nov 16, 2008 at 01:42 UTC | |
by zwon (Abbot) on Nov 15, 2008 at 23:00 UTC |
In Section
Seekers of Perl Wisdom