> Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
> Date: Thu, 2 Jan 2003 19:21:04 +0100
> Cc: [EMAIL PROTECTED]
> From: Arthur Bergman <[EMAIL PROTECTED]>
> X-SMTPD: qpsmtpd/0.20, http://develooper.com/code/qpsmtpd/
> 
> Hello,
> 
> I just got a question from Lee Pumphret regarding Hook::Scope POST in 
> loops.
> 
> Currently it treats every iteration as a scope entry and scope exit so.
> 
> for(1..3) {
>       POST { print 2 };
>       print 1;
> }
> 
> will print "121212",
> 
> Since perl6 seems to have a NEXT {} block for doing this, how is POST 
> and CATCH supposed to
> be used in conjunction with loop scopes.

The difference between POST and NEXT is simply that POST fails to
refrain from executing after the final iteration, while NEXT does not.

You example is correct.  In addition,

    for 1..3 {
      print 1;
      NEXT { print 2 }
    }

Prints "12121".

NEXT is really a kind of PRE block, contrary to what the example may
lead you to believe.  So, 

    for 1..3 {
      print;
      NEXT { print }
    }

Prints "12233", not "11223".

As I recall, CATCH can be used inside any block that contains an
expression that may throw an exception.

    for 1..Inf {
        die "Bonkers";
        CATCH {
          print;
        }
    }

Prints "Bonkers".

I hope this clarified things.

Luke

Reply via email to