Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by Argel (Prior)
on Jan 12, 2011 at 23:59 UTC ( #882008=note: print w/replies, xml ) Need Help??


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

Don't you think the "foreach" comment is nitpicking a bit? It's an alias to "for" and when performing the loop the the Perlish way the phrase "for each element" makes more sense than "for element". Meanwhile, when using it the repressed memory inducing, nightmarish C-style way, the phrase "for this series of numbers" is a better fit. In my experience, "foreach" is easier for people new to programming to grasp and it makes it easier to wean C-junkies off of the C-styled for loops.

Elda Taluta; Sarks Sark; Ark Arks

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

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

    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").

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://882008]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-02-22 23:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (300 votes). Check out past polls.

    Notices?