* David Green <david.gr...@telus.net> [2008-12-18 19:45]:
> Well, I prefer a built-in counter like that, but I thought the
> point was that you wanted some kind of block or something that
> could be syntactically distinct?

No, that would only be a means to the end. That end is simply to
not repeat myself in writing honest code. And I just realised how
to best do that in Perl 5:

    goto INVARIANT;

    while ( @stuff ) {
        $_->do_something( ++$i ) for @stuff;

        INVARIANT:
        @stuff = grep { $_->valid } @stuff;
    }

I am not sure why this works, to be honest. That is, I don’t know
whether it’s an intentional or accidental feature that execution
doesn’t merely fall off the end of the loop body after jumping
into the middle of it, but loops back to the top, despite not
having executed the `while` statement first.

But it does work.

And it says exactly what it’s supposed to say in the absolutely
most straightforward manner possible. The order of execution is
crystal clear, the intent behind the loop completely explicit.

-- 
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
&Just->another->Perl->hack;
#Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to