perl_boy, per Re: can't read the 2nd input file;12 new versions of PORT-STATE-SERVICE+IP;14 in all;3 disk,11 memory (part 2) where you said that you "got no replies as an instruction/statement/command that would allow me to return FROM WITHIN the label", you still seem to not have gotten the point: that's not something you need to be able to do. If you think you want to have a goto and return , you haven't thought through the problem correctly, because goto-followed-by-return is the ancient programming practice which was superseded by functions/subroutines. If you think you need a goto at all in Perl, you probably haven't thought through the problem correctly.

I'm not the expert on such things, and thought that everyone else already explained it well enough. But since you are still confused, I am giving it a go.

In your first example, goto-0.pl, I cannot imagine how you think it would work. What is the print sequence that you expect if the "goto-label / return-from-label" worked as you want it to?

In your second example, goto-1.pl, I believe you want to set a to 0, then skip over the "LOOP" and its two lines of commands, then run the while loop. In the while loop, you want to jump into the "LOOP" section, print and increment, then return to the while. If I have interpreted correctly, this would print

0---- 1---- 2---- ... 17---- 18---- 19----
But that convoluted logic could be more simply written as
#!perl use 5.012; # strict, // use warnings; my $a = 0; while($a < 20) { mySubroutine(); print "----\n"; } sub mySubroutine { print $a++; # implied "return" from subroutine; you could make it explicit on +this line if you really wanted to } exit;
Here, the logic is much more explicit. Basically, I moved your "LOOP" label with its two lines of code to be a subroutine instead of a label.

Actually, my guess is that both goto-0 and goto-1 were supposed to accomplish the same task. In which case my implementation works for either.

I cannot go to your mooo URL, because that domain is blocked my IT department, so I cannot see a more practical example of what you're trying to accomplish. But I am quite certain that nearly anything you claim you want to do with goto-labels and return-from-labels would be more practically implemented with subroutines. (There are a few "goto-like" constructs that would be better with nested loops, labels on loops, and judicious use of last LABEL, next LABEL, and redo LABEL) .... But since I cannot see your website (and I probably wouldn't have understood the examples there anyway, if your goto-0 is any indication the examples there), I cannot offer concrete implementations for other constructs if my working example doesn't do what you need.

I think if you really want more help finding an alternative to the non-existent goto/return pair, you will have to provide pseudocode showing the logic you think you need, using only prints and use goto and pseudoReturn in your pseudocode, and maybe one variable to show where you are in the flow or provide decision-making. Then show us the example output you desire from that pseudocode. Then we can, if we understand your example, show actual working perl code which will provide the same output, using either subroutines or nested while loops (or both). Or maybe give pseudocode with embedded line numbers, then list the sequence of line numbers that you think would run based on that pseudocode. But if you just direct us to an external website, then some of us (including me), will not be able to do anything more for you.


In reply to Re: how to return from a goto ? by pryrt
in thread how to return from a goto ? by perl_boy

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.