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:

# -- 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; }
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.

In reply to Re: How can I return to main loop, not to caller? by ambrus
in thread 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.