in reply to Re^6: 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 -- typing four more letters isn't a big deal. And like I said, people just learning to program in my experience tend to "get it" sooner with "foreach". Quite frankly, I wish they were distinct so we could discourage "for" loops and encourage "foreach" loops without any ambiguity -- useful when dragging those kicking and screaming, die hard C coders into the world of Perl!!! :-)

Elda Taluta; Sarks Sark; Ark Arks

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

Replies are listed 'Best First'.
Re^8: eof not recognised when applying diamond operator to invocation arguments?
by ikegami (Patriarch) on Jan 14, 2011 at 17:49 UTC

    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.

      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.