So, important history lesson/qualification:
https://dx.doi.org/10.1145%2F362929.362947
Considered harmful

Long story short: old languages didn't have good Loop Control or early return, so they needed goto. Perl has them, so you are probably doing something bad if you need to use it. So consider how you can refactor to avoid it. This is coming from a Fortran hacker, so this warning should not be taken lightly.

To do what you have asked, the code is:

#!/usr/bin/perl use strict; use warnings; use 5.012; my $gas_cost = 1.5; if ($gas_cost < 1) {goto ENDING_BRACE }; say "Intermediate"; ENDING_BRACE: say "After";
which appears to be your case 1, so I think you have transcribed your problem badly. I do not know what code you are trying to emulate, but I would probably write your code as:
{ last if $gas_cost < 1; stuff here } continue here
or
func(); continue here; sub func { return if $gas_cost < 1; stuff here }
or even
if ($gas_cost >= 1) { stuff here } continue here
Or a myriad of variations. The difference between your proposal and any of the above is only scoping, and that can be addressed as well if you share your real code with us.

You may also find How does 'goto LABEL' search for its label? informative.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


In reply to Re: How to no goto or gosub by kennethk
in thread How to no goto or gosub by oldcity

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.