On 4/20/07, Paul Johnson <[EMAIL PROTECTED]> wrote:
snip
> The grep clearly states that I am looking for something and its block
> tells me what the criteria are.

There are times where this list needs webctams.  I'd love to have been
able to have seen you as you wrote that since I find it hard to believe
that anyone could have done so whilst keeping a straight face ;-)

No, I really do think it is better code that expresses the intent;
however, I don't like the goal behind code in the first place.  How
often do you take each third element of list?  If you are doing that
then you are most likely doing something else wrong farther up in your
code.


I presume that in your second example you should really be comparing
against

  for (my $i = 0; $i < 10; $i += 3) {
      func($i);
  }

which just seems so much clearer to me.

if your goal is to produce 0, 3, 6, and 9 then yes, it is somewhat
clearer, but the very fact the you have a 10 there instead of a 9
points to the off-by-one errors that tend to plague the C-style for
loop.  Unfortunately we will have to wait until Perl 6 for the better
solution:

for 0 .. 9 : by 3 -> $i {}

Fortunately, TIMTOWTDI, but with any luck I won't be maintaining your
code ;-)

I probably wouldn't write that code.  I would fix whatever was causing
me to have to take every third element of a list.


Anyway, there seems to be a little confusion about whether for or
foreach were going to be removed from the language.  The main point I
wanted to make was that foreach is not going away.  Neither is for.  At
least, not in Perl5, which will still be around for a long time.  They
are still synonyms, and any code written now and using either of these
constructs will continue to work under all Perl5 releases.

The trend going forward is to do away with foreach in favor of for, so
the question becomes "is there any good reason to type four more
letters?"


--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to