in reply to Doing "it" only once

Flags aren't always a bad thing.

while ( ... ) { if (!$flag && check_whatever()) { do_whatever(); $flag = 1; } }

I'd suspect that the best way of putting this into the core would be simply by setting/checking a flag at the C (or Parrot, I guess) level instead of the Perl level. I suppose that, after a single execution you could actually remove the relevant ops from the tree altogether, but I'd have to wonder at the efficiency of that in all but very long running loops.

Making it a language feature in Perl 6 might make some sense as it would allow the programmer to avoid the use of flag. I don't see the point in jumping through any hoops to implement this in Perl 5 though.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: Doing "it" only once
by grinder (Bishop) on Sep 22, 2005 at 08:32 UTC
    Flags aren't always a bad thing.

    They are if you choose a terrible name :)

    while ( ... ) { if ( !$done_whatever && check_whatever()) { do_whatever(); $done_whatever = 1; } }

    There, I feel much better now.

    • another intruder with the mooring in the heart of the Perl