in reply to Re^3: Useless use of private variable in void context
in thread Useless use of private variable in void context
Perl for loops are more compact, easier to understand and safer than a C for loop. All these arise from the Perl for loop having fewer moving parts:
for my $element (@elements)
compared with the equivalent C loop header:
for (my $index = 0; $index <= @elements; ++index) { my $element = $elements[$index];
If what you want to do in the loop is use $element (and in the vast number of situations it is) then the Perl loop 'wins' by a country mile.
The biggest problem with C style loop is ensuring that you don't introduce off by 1 errors. It's easy to do and can be hard to spot.
|
|---|