That goto discussion seems to be saying that goto a subroutine ought only to be used in the most magical circumstances.
More to the point is to consider exactly when you would need to use it, and when you care. The circumstances are when you want to fake "caller" to the sub being called, i.e. make your current subroutine invisible.

One circumstance when you would do this is in an AUTOLOAD subroutine that is generating new subroutines on the hoof (or loading them in from files). Suppose we have a package Foo and function bar, which does not exist at the start of the program. The first call to Foo::bar results in a call to Foo::AUTOLOAD, with $Foo::AUTOLOAD set to 'Foo::bar'.

The AUTOLOAD code creates a new subroutine and puts it into package name space as Foo::bar, so future calls to Foo::bar call this sub directly. We want the first call to Foo::bar not to see its caller as Foo::AUTOLOAD, but as the real caller. In order to achieve this, AUTOLOAD does a goto &Foo::bar once it has finished.

Other times when you might need to fake "caller" are more arcane, such as what Hook::LexWrap does internally. You also need to use these techniques if you are writing a debugger, profiler or such like.

Hopefully this has explained the "magic" in this case.

--
I'm Not Just Another Perl Hacker


In reply to Re: Re: Entering and exiting subs in style by rinceWind
in thread Entering and exiting subs in style by bradcathey

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.