Eyck has asked for the wisdom of the Perl Monks concerning the following question:

I relatively frequently use stuff like 'next'&'last' to simplify loops. This makes code more readable but caused me to hit strange bug(?) in labeling code. Due to some night brain fart I created something like this:
LOOP: ... ... ... redo LOOP unles($var)
Woohaa..., where did it come from?...

Anyhoo... I haven't noticed what I've done, until recently I saw something like this: 'Label not found for "redo LOOP",

After some googling I found some old bug, that causes 'redo' to lost track of blocks if 'goto' is used. I don't use 'goto', but I figured that there may be some esoteric connection between my problem and bug #19061, and replaced 'redo' with 'goto', and the problem vanished.

So, the question would be - what's the difference between 'redo' and 'goto'?

And how would one go about hunting such bugs? Should one care at all? After all, I don't need such construct at all.

Title editted by tye to make it more than one word

Replies are listed 'Best First'.
Re: Redo
by Abigail-II (Bishop) on Mar 11, 2004 at 13:31 UTC
    So, the question would be - what's the difference between 'redo' and 'goto'?
    A redo is looping construct (while, for, until, bare-block) bound, while goto isn't. Your code doesn't have the redo in a looping construct - hence the message.

    Abigail

Re: What's the difference between 'redo' and 'goto'? (label location)
by tye (Sage) on Mar 11, 2004 at 16:46 UTC

    The difference is that "redo LOOP" expects "LOOP" to be a label assigned to a loop (by placing the label right before the start of the loop) while "goto LOOP" just expects "LOOP" to be a 'nearby' label.

    Since you don't tell us what that first "..." really is, I can't say whether "LOOP:" is right before the start of a loop. However, your indentation makes me suspect that, if your "LOOP:" is right before the start of a loop construct, then your "redo LOOP" is not inside of that loop (the other requirement for 'redo').

    My testing shows that 'Label not found for "redo LOOP"' is the result for both cases (using a label that is not assigned to a loop or using 'redo' outside of the named loop).

    - tye        

      Thanks, you're right. The code looked like this:
      LOOP: while (...) { } redo LOOP if (stuff);

      This check used to be in the middle of the loop. I guess it just shows that one should always take a step back even before making this teeeny-tiny change to a code.