Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^6: C-style for loopby GrandFather (Saint) |
on Nov 15, 2008 at 23:08 UTC ( [id://723859]=note: print w/replies, xml ) | Need Help?? |
Absolutely if the point you are trying to make is that there is a tiny execution penalty in this rather artificial case for using the Perl style for loop. An interesting test is to change the loops from reverse to forwards and see where the differences lie. For the C style for loop you need to change every part of the loop header in a major way and you have to think a while to ensure the range is what you want:
For the Perl loop just deleting the reverse does the trick and the range is still completely clear. Oh, and now the Perl loop overhead is less than the C loop overhead:
Considering how small the overhead of using reverse is and how much more maintainable the Perl loop is you have done an admirable job of demonstrating why in the general case the Perl for loop is much better than the C style for loop. Perl reduces RSI - it saves typing
In Section
Seekers of Perl Wisdom
|
|