http://www.perlmonks.org?node_id=7976


in reply to RE: RE: Number of times I've used goto in Perl
in thread Number of times I've used goto in Perl

Ok, perhaps the question should read: "How many times have you inserted the 'goto' keyword into one of your scripts?" CGI.pm and most others simply use the goto as part of the AUTOLOAD feature, so I let them slide....but, glancing through the standard modules, there are some exceptions: sigtrap.pm, autouse.pm, and (oh no!) even good old Carp.pm use 'goto' as a way of reaching another part of their script. Bleh! I'm still at 'never.'
  • Comment on RE: RE: RE: Number of times I've used goto in Perl

Replies are listed 'Best First'.
RE: RE: RE: RE: Number of times I've used goto in Perl
by btrott (Parson) on Apr 19, 2000 at 02:11 UTC
    Point taken. :)

    But in the case of Carp, my Carp.pm uses goto in the same magical way that it's used in AUTOLOAD:

    goto &longmess;
    The purpose being that this magical goto erases the calling function from the call stack, which is exactly why it's used here: since longmess dumps out a stack trace, we don't want shortmess showing up in the call stack.

    So you should let Carp.pm slide, too. :)

    BTW, I like the perlfunc entry for goto:

    goto - create spaghetti code
      OK, I'll let Carp slide as well. :) (Is this thread nested enough yet?)
RE: RE: RE: RE: Number of times I've used goto in Perl
by Anonymous Monk on Apr 20, 2000 at 22:21 UTC
    Maybe the question should read "what is the most goto's you've used in a single script/program". I answered "more than ten" even though I rarely use goto, just because I've written so many scripts. Adding a goto is usually better than duplicating code and/or re-arranging a large and complex loop.