in reply to Re: Useful uses of redo?
in thread Useful uses of redo?

I use for(;;){...} rather while(1){...} (less lying), but I like this redo idea. I didn't know it could be used on bare blocks before this thread. However, I'm concerned about the lack of visual junk at the top that people expect for loops. Do you think there's any penalty or side-effects to using do { ... } instead of { ... }?

Replies are listed 'Best First'.
•Re^3: Useful uses of redo?
by merlyn (Sage) on Aug 26, 2004 at 19:41 UTC
    Do you think there's any penalty or side-effects to using do { ... } instead of { ... }?
    Other than it won't work? That's a pretty severe penalty. last/next/redo do not pay attention to do-blocks.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re^3: Useful uses of redo?
by davido (Cardinal) on Aug 26, 2004 at 19:46 UTC

    There isn't necessarily any reason not to use do { ... }, as long as you realize that a do block isn't 100% like bare blocks. I look at do blocks kind of like immediately executing subroutines minus the parameter list, since do blocks have return values vaguely similar to subs.

    If you're concerned about the visual ambiguity of a bare block with a redo inside it, you can always start it off with a label, as in:

    LOOP: { # do some stuff redo; }

    However, even though while(1) (and even for(;;)) sort of perpetrates a fib, it is still more flexible to use such constructs over the bare block / redo method, because bare blocks don't support continue, occasionally useful with explicit loops.


    Dave