Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by ikegami (Patriarch)
on Jan 13, 2011 at 00:49 UTC ( [id://882014]=note: print w/replies, xml ) Need Help??


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

Why is it always C-style loops (usually used as counting loops) vs list iterator loops? Perl-style counting loops are always ignored. By your argument, one should use for for them. Others argue they are just optimisations of list iteration loops. It just goes to show how meaningless the choice of keyword is. In fact, you'll realise after a while that you never rely on the keyword anyway, so you should just use what's simpler ("for").

Replies are listed 'Best First'.
Re^7: eof not recognised when applying diamond operator to invocation arguments?
by Argel (Prior) on Jan 14, 2011 at 17:07 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 -- 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

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 02:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found