Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: how to return from a goto ?by pryrt (Abbot) |
on Apr 06, 2022 at 14:19 UTC ( [id://11142733]=note: print w/replies, xml ) | Need Help?? |
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 But that convoluted logic could be more simply written as 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 Section
Seekers of Perl Wisdom
|
|