in reply to Re^3: how to avoid nested looping?
in thread how to avoid nested looping?

What version of Perl are you using and on which platform? perl -V would be nice. I'm not saying map is faster, but then, I'm not really worried about it. I'm more worried about code correctness and maintainability.

One interesting thing about map and friends which is not appreciated enough is how map says "do this for everything in the list" when foreach says "do this to each thing in the list." It's a subtle distinction, but one study of programming discovered that programmers tend to make fewer errors when using commands that operate on an entire set instead of looping constructs that operate on individual members of the set. Unfortunately for most programmers, we're given tools for the latter while the former are often considered "advanced" when in reality their simpler. We get taught the bad way and we get used to it. Go figure :)

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^5: how to avoid nested looping?
by lidden (Curate) on Feb 04, 2005 at 12:02 UTC
    I tried bgreenlees program and this is what i got.

    This is perl, v5.9.1 built for i686-linux.
    Rate map foreach map 313/s -- -43% foreach 552/s 76% -- Rate map foreach map 313/s -- -44% foreach 558/s 78% --

    This is perl, v5.8.3 built for i686-linux
    Rate map foreach map 308/s -- -47% foreach 581/s 89% -- Rate map foreach map 308/s -- -47% foreach 578/s 88% --
Re^5: how to avoid nested looping?
by bgreenlee (Friar) on Feb 04, 2005 at 13:55 UTC

    That was run under 5.8.5. Full -V output:

    -b

Re^5: how to avoid nested looping?
by tphyahoo (Vicar) on Feb 04, 2005 at 11:27 UTC