From: Gyepi SAM <gy...@praxis-sw.com>
   Date: Mon, 8 Apr 2013 15:02:55 -0400

   On Mon, Apr 08, 2013 at 10:54:47AM -0400, Ricker, William wrote:
   > Have we mentioned the other solution? 
   > The Implicit loops of map {block} list; should produce more
   > optimized code and reads better too.

   map should produce better code and does reads better but it also
   iterates the entire list and you can't break out of it . . .

Not quite true, as you can "goto" a label outside of the block:

    sub find_odd {
        # Return the first odd argument.
        my (@values) = @_;

        my $result;
        map { $result = $_ and goto LAST
                  if $_ & 1;
        } @values;
      LAST:
        return $result;
    }

It's hard to think of a case where this would be better than a simple
loop, which is both smaller and more readable.  However, this technique
also gives you an early exit when mapping over a tree recursively.

                                        -- Bob Rogers
                                           http://www.rgrjr.com/

_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to