Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The three-part for statements that Perl inherits from C are needed only for unusual loop control behaviour, such as iterating by twos, or in an irregular sequence. But even in such cases, these C-style loops provide that unusual behaviour in an obscure and harder-to-maintain way.
That's because the iterative behaviour of a three-part for statement is emergent, rather than explicit. In other words, the only way to know what a loop like:
for (my $n=4; $n<=$MAX; $n+=2) {
print $result[$n];
}
is going to do is to sit down and work out the abstract logic of the three components:
"Let's see:
nstarts at 4, and continues up toMAX, incrementing by two each time. So the sequence is 4, 6, 8, etc. So the loop iterates through all the evenn's from 4 up to and includingMAX(ifMAXitself is even)."