Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^2: which loop is betterby Ven'Tatsu (Deacon) |
on Oct 04, 2004 at 17:11 UTC ( [id://396294]=note: print w/replies, xml ) | Need Help?? |
I dissagree. There are cases where foreach (LIST) is better than for (EXPR;EXPR;EXPR), but the 3 argument for can do things that foreach can't. When I program in C or Java 50-80% of my for loops are itterating over an array (though use itterators far more in Java), what I would use foreach to do in Perl. In the case of itterating over every element of an array foreach more accurately expresses my intent. I could use for, and it would work, but for tends to be more cluttered, and therefore IMO less readable. is basicly the same as I find the first simpler and the second more powerful but more noisy for most uses. If you really feel that Larry never includes 'inferior constructs' in Perl then you don't see any thing wrong with writing as They do the same thing, and I understand both of them. So obviously since they are both in Perl they are both equaly correct. </sarcasm> My guess is Larry included both 'better' and 'inferior' constructs because sometimes better is too specific for a task, and only inferior will do the job (such as Switch's use of goto). And it should be up to the programmer to know which to use.
In Section
Seekers of Perl Wisdom
|
|