laziness, impatience, and hubris | |
PerlMonks |
Re: Style and Preference on Loopsby cdarke (Prior) |
on Aug 12, 2011 at 15:16 UTC ( [id://920041]=note: print w/replies, xml ) | Need Help?? |
The first style, the C style counting loop, requires that you maintain your own iterator ($i), ensure it is always incremented, and check the bounds of the array. With the second loop, perl does all that for you. I expect the second is more efficient, although I have never measured it and I doubt the difference is huge, but I prefer the second because of two principles: 1. Less code generally means fewer bugs. 2. Why have a dog and bark yourself?
In Section
Seekers of Perl Wisdom
|
|