Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^9: eof not recognised when applying diamond operator to invocation arguments?

by Argel (Prior)
on Jan 14, 2011 at 23:48 UTC ( [id://882427]=note: print w/replies, xml ) Need Help??


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

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

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

Replies are listed 'Best First'.
Re^10: eof not recognised when applying diamond operator to invocation arguments?
by BrowserUk (Patriarch) on Jan 15, 2011 at 00:52 UTC

    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.
Re^10: eof not recognised when applying diamond operator to invocation arguments?
by ikegami (Patriarch) on Jan 17, 2011 at 16:54 UTC

    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

        Good grief!! Even the Perl documentation makes the distinction between the two:

        I didn't say what you do makes no sense; I said the reason you gave makes no sense. It doesn't mean there are no other reasons that do make sense.

        but the documentation starts off by using "for" to describe the C-style form of "(;;)

        C-style loops are almost always used as for loops, so that's pretty accurate (although they are really just while loops.)

        and "foreach" to describe the Perl-style form of "$var (list)".

        Actually, the documentation isn't as clear as your purport it to be. It appears that section was written to describe that syntax, but it says "The foreach loop iterates over a normal list value and sets the variable VAR to be each element of the list in turn." for VAR (EXPR..EXPR) doesn't match that definition.

        The Perl documentation is one of those that seem to forget about Perl-style for loops.

        So I'm perfectly in line with how the Perl documentation describes them.

        But I'm asking about that case that's not documented! So we've looped back to here.

        My point about discouraging "for" loops was if the two were actually two distinct looping styles

        If the two were actually two distinct looping styles, ...? Part of that sentence seems to be missing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://882427]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-19 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found