Hello. I am looking for a way to return-to-main, as opposed to return-to-caller. Is there a simple way to do this?

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.