in reply to Re^2: looping in 2d array
in thread looping in 2d array

This is true. And beside the point :-)

My point was to let Perl worry about the incrementing and bounds checking, eliminating many common problems such as accidently using the wrong counter or off-by-one errors. Personally, I find the keyword foreach coupled with a clear, recognizable variable name to be more readable than the for keyword which I'm familiar with from several inferior languages. Although I know perfectly well that Perl will do what I mean either way, I keep a clear distinction between the two to avoid confusion.

-- FloydATC

Time flies when you don't know what you're doing

Replies are listed 'Best First'.
Re^4: looping in 2d array
by ww (Archbishop) on Nov 02, 2014 at 15:33 UTC

    Sorry if my remark gave offense... but my point is that both for and foreach deal equally well -- and effectively identically -- with Linguist's problem as indicated by the example code in my previous post. Each will cheerfully increment and/or bounds-check (stricken when I engaged brain and realized that I haven't offered an example of bounds-checking in a Perl-style for loop nor can I think of one now) with either C-style or Perlish iterators.

    You believe your mnemonic use of different words is useful to you. I, therefore, believe that para 1 is probably absolutely valid for you. My objection is that para 1 of your earlier post is only a personal opinion (as is this para and the next)... and is phrased in a manner likely to be "misleading" on any question of functionality.

    "Yes," "ja" and "oui" are equivalents even though they are different words ... but addressing a multi-lingual audience it would surely be unwise to suggest that English speakers would be better served in daily life by using "oui" or that Germans should say "oui" or "yes" as an affirmative.


    ++$anecdote ne $data


Re^4: looping in 2d array
by AnomalousMonk (Archbishop) on Nov 02, 2014 at 21:51 UTC
    This [distinction between for and foreach] is ... beside the point ...

    Given that Linguist identifies him- or herself as "... new to PERL ...", I think ww's point is very apt. As used above, the for versus foreach distinction is a bit of Perl jargon that needs to be identified as such to the novice Perler. If it is not, it leads to questions like "Ok, so what's the difference between for and foreach?" This is a question on a par with "When is a door not a door?", except it has no amusing punchline; instead, there is only the tragic realization that you've just thrown away a few-score seconds of your life pondering a stupid question.

    I had originally not up-voted ww's posts on this point, but have now done so as a show of solidarity forever! against jargon masquerading as idiom.