in reply to given == for?

Besides looping, foreach allows assigning the topic to a variable (foreach my $foo (...)), C-style loops (foreach (my $i = 0; $i < ...; $i++)) and its use a statement modifier. Furthermore, you cannot use a continue block, next, last or redo with given.

At the moment, I can't think of anything given gives you that for/foreach doesn't.

Replies are listed 'Best First'.
Re^2: given == for?
by moritz (Cardinal) on Jul 22, 2010 at 12:41 UTC
    At the moment, I can't think of anything given gives you that for/foreach doesn't.

    Catching break.

    If you nest a for-loop and a given, you can selectively escape them with last and break.

    (OK, you can do that with labels too).

    Perl 6 - links to (nearly) everything that is Perl 6.
      If you nest a for-loop and a given, you can selectively escape them with last and break.

      (OK, you can do that with labels too).

      At least last allows labels - break doesn't.