OK, awreddy! The wisdom elsewhere in this thread prompts me to expand what appears to be my minority response to the OP:

First, for clarity, allow me to amend "For the purpose ... ahead and GOTO." to read: "For the NARROW purpose you've outlined, perlitical correctness is not the issue. "Perlitically correct" be damned! If it works, go ahead and GOTO (sic) (but don't get in the habit)!

Yes, even that runs counter to convention wisdom (and I readily acknowledge that the conventional wisdom is wise. (In fact, the bit of nonsense below represents the first time I've even considered using goto in years.)

But I read the OP, the Seeker has a suite of tests of "human reaction," each of whose members stands alone. IOW, I conceive each test to be fundamentally self-contained and (perhaps) presented in a fixed sequence; that his offer to re-run the tests would occur only upon completion of the suite.

In such a case, concerns about spaghetti code, readability, resetting of variables, and all the other usual problems with goto are (or can be, in a(n otherwise, if you must) well-written program can be moot.

The script below, while not reflecting precisely the constraints above, may invite comments... or even second thoughts???

use strict; use warnings; my @array = qw/a b c/; START: for my $item(@array) { my $sub_call = "&" . $item; eval ($sub_call); } sub quit { print "Would you like to do that again? 'y' or 'n'\n"; if (<STDIN> =~ /y/) { goto START; }else{ print "OK, done.\n"; exit; } } sub a { print "Type 'blue' to continue:\n"; if (<STDIN> =~ /blue/i) { return 1; } else { quit(); } } sub b { print "Cross your fingers and type 'foobar' to continue:\n"; if (<STDIN> =~ /foobar/i) { return 1; } else { quit(); } } sub c { print "To quit (prematurely), type 'no'\n"; if (<STDIN> =~ /no/) { exit; } else { goto START; } }

For "nonsense" constructed specifically to use a goto, this seems to me (YMMV) clear and utterly without 'strange actions at a distance.'

FTR, in NO way does it rebut the correctness of deprecating goto; rather, it's intended as a reminder that there are -- occasionally -- times to violate conventional wisdom and ways to sidestep the underlying evil that norm seeks to avoid.


In reply to Re: GOTO or not GOTO by ww
in thread GOTO or not GOTO by jflevi

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.