After thinking about this for a while, I realized the biggest Perl reason why
foreach, in my mind, is more readable than
for. It's the fact that so much in Perl is predicated on lists.
map,
grep,
push, etc ... there's so much about lists. Then, all of a sudden, I go from dealing with a list to dealing with the implementation of a list. I don't care about index numbers - I care about the holistic, organic list. :-)
To reply to your node, I have read Code Complete and do remember both sections you refer to.
The indentation study ... it was interesting, but he was using it, in my opinion, more to discuss that indentation systems aren't arbitrary vs. readability issues.
As for the looping mechanisms ... for-loops do package a lot in a single place. That's their benefit and their Achilles' heel. Yes, I do have a beef against for-loops, primarily because they've been abused way too much in C. I remember reading some for-loops where the conditions had more lines than the block itself!
I do use for-loops when they make sense in Perl. I prefer the foreach construct (but will use the word 'for' instead of 'foreach'), primarily because it says only what it needs to say. I'm a fan of minimalist programming - say only what you need to say and no more. for-loops tend to say more than what's needed.
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.