in reply to How can I return to main loop, not to caller?
You can safely use goto, as it does clear the call stack (this is perl, not basic). A somewhat more readable way might be to use redo or next, but you should know that redo is essentially the same as goto except that goto allows labels without loops and that only goto allows computed labels. (Update: they're not the same, redo jumps inside the loop, goto jumps before the loop. Redo is the same as a goto to a label that is placed the first thing in the loop body.)
The drawback of gotos and labels is that there are some language constructs that you can not leave with goto; but as far as I know, you can jump out from anything with die/eval. Goto will also warn you when you exit functions, but this warning is only informational, you can safely turn it off.
Thus, you can use some code like:
Don't reuse the label MAIN_LOOP in any function that can be called from the main loop or else myerror will jump there if called.# -- next MAIN_LOOP jumps here unless there's a continue block too MAIN_LOOP: while (<>) { # -- redo MAIN_LOOP or goto MAIN_LOOP jumps here .... a() .... } sub a { .... myerror (); .... } sub myerror { redo MAIN_LOOP; }
|
|---|