I am writing a small and simple interpreter, which just aborts and prints a simple error message if it finds any errors, then waits for you to try again. Error traps can be in any level of sub-sub-etc-routine, and I'm looking for a simple way to go directly back to the keyboard-input main loop without letting the return stack fill up to infinity...
'die' and 'exit' will quit the Perl script, so they aren't what I want; 'goto' won't clear the return stack, so I don't think this is a good choice either. Can you help?
Thanks!
SEI
pseudocode example:
pseudocode example: # this is the (infinite) main loop, which takes a line of # keyboard input and processes it, until the program is # killed while (<>) { # call subs here if (foo) { &a(); next; } elsif (bar) { &b(); next; } else { &c; } } sub a { # do stuff if (divide by zero error) &myerror(message); &c(); # do more stuff return value; } sub b { # do a lot of stuff if (format is wrong) &myerror(message); # do more stuff return hash; } sub c { # do stuff if (type mismatch) &myerror(message); &b(); return list; } sub myerror { # print error message # and now I want to go straight back to the main # loop, no matter how many levels of subroutines # deep this &myerror call was, as if the program # were just starting (with the single exception # that I want to keep all the program's # global variables intact) }
In reply to How can I return to main loop, not to caller? by SEI
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |