in reply to Re^7: eof not recognised when applying diamond operator to invocation arguments?
in thread eof not recognised when applying diamond operator to invocation arguments?

Actually, I do use "for" for C-style iterations and "foreach" for the more Perlish iterator loops! I like to use what "feels" right

Did you read the post to which you replied? ("Why is it always C-style loops (usually used as counting loops) vs list iterator loops? Perl-style counting loops are always ignored.")

So what do you use for Perl-style for loops?

for (1..5) { say; } foreach (1..5) { say; }

Quite frankly, I wish they were distinct so we could discourage "for" loops and encourage "foreach" loops without any ambiguity

For loops are very important and should not be discouraged in the least. Just the C-style ones are hard to read.

  • Comment on Re^8: eof not recognised when applying diamond operator to invocation arguments?
  • Download Code

Replies are listed 'Best First'.
Re^9: eof not recognised when applying diamond operator to invocation arguments?
by Argel (Prior) on Jan 14, 2011 at 23:48 UTC
    Very sorry, didn't get that that's what you meant! I use "foreach" for those, though I rarely run into that situation. The further away I get from the actual list of elements I will loop over the more likely I am to switch from "foreach" to "for". So the C-style version obviously is pretty distant from the actual list -- I mean, there are three sections in the parenthesis whose content when combined specify what the list of numbers will look like. Hope that makes some sense?

    Elda Taluta; Sarks Sark; Ark Arks

      Syntactically and semantically, the two are interchangeable. There are no reasons for requiring the use of one over the other.

      Which makes any attempt to convey some meaning through given uses of the two at best subliminal. At worst ...


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      I mean, there are three sections in the parenthesis

      So you choose to make the C-style for loop look difference from the others because it looks different? No, that doesn't make much sense to me.

        Good grief!! Even the Perl documentation makes the distinction between the two: For Loops and Foreach Loops. Yes, it does go on to mention that "foreach" is a synonym for "for", but the documentation starts off by using "for" to describe the C-style form of "(;;)" and "foreach" to describe the Perl-style form of "$var (list)". And that includes separate, distinct entries in the table of contents -- i.e. they are listed as two different styles of looping, which is only clarified under "Foreach". So I'm perfectly in line with how the Perl documentation describes them. Not saying you guys are wrong -- but the original point was that it's a stylistic choice.

        My point about discouraging "for" loops was if the two were actually two distinct looping styles (i.e. that "foreach" was not a synonym for "for", so that "for" could only be used for C-style for loops). Sorry if there was any confusion over that.

        Elda Taluta; Sarks Sark; Ark Arks