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.
foreach (@array) { dosomethingto($_); }
is basicly the same as
for (my $i = 0; $i < @array; $i++) { dosomethingto($array[$i]); }
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
my $fs = ''; for (my $f = 0; $f < 10; $f++) { #last if $f == 7; next if $f == 5; print "f: $f\n"; $fs .= "$f "; redo if length($fs) == 6; } print "fs: $fs\n";
as
my $gs = ''; FOR_INIT: my $g = 0; goto FOR_TEST; FOR_NEXT: $g++; FOR_TEST: goto FOR_LAST unless $g < 10; FOR_REDO: #goto FOR_LAST if $g == 7; goto FOR_NEXT if $g == 5; print "g: $g\n"; $gs .= "$g "; goto FOR_REDO if length($gs) == 6; goto FOR_NEXT; FOR_LAST: print "gs: $gs\n";
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 reply to Re^2: which loop is better by Ven'Tatsu
in thread which loop is better by TheMarty

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.