Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by IndyZ (Friar)
on Apr 19, 2000 at 00:43 UTC ( #7972=note: print w/ replies, xml ) Need Help??


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

I think this a a test by vroom to see who deserves their monk status. Anybody who says that they've uses a goto loses 75% of their XP.


Comment on RE: Number of times I've used goto in Perl
RE: RE: Number of times I've used goto in Perl
by btrott (Parson) on Apr 19, 2000 at 00:54 UTC
    Actually, if you've ever done much module/OO programming, you've probably used goto quite a lot, particularly if you write AUTOLOAD functions. From perltoot:
    When Perl tries to call an undefined function in a particular package and that function is not defined, it looks for a function in that same package called AUTOLOAD. If one exists, it's called with the same arguments as the original function would have had. The fully-qualified name of the function is stored in that package's global variable $AUTOLOAD. Once called, the function can do anything it would like, including defining a new function by the right name, and then doing a really fancy kind of goto right to it, erasing itself from the call stack.
    As such goto is used in quite a few modules, core or otherwise. CGI.pm, for example.
      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.'
        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
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://7972]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-07-10 08:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (203 votes), past polls