develooper Front page | perl.perl5.porters | Postings from November 1999

Re: [ID 19991115.012] Localization and goto()

Thread Previous | Thread Next
M.J.T. Guy
November 16, 1999 07:05
Re: [ID 19991115.012] Localization and goto()
Message ID: wrote
> $a = 5;
> sub a { print $a }
> sub b {local $b = 9; goto &a}
> b;
> This prints 5.  "Should" not it print 9 instead?

That was my initial reaction, but the documentation suggests rather
strongly that *all* effects of b() are undone:

            The `goto-&NAME' form is highly magical, and substitutes
            a call to the named subroutine for the currently running
            subroutine. This is used by `AUTOLOAD' subroutines that
            wish to load another subroutine and then pretend that
            the other subroutine had been called in the first place
            (except that any modifications to `@_' in the current
            subroutine are propagated to the other subroutine.)
>>>>>>>     After the `goto', not even `caller()' will be able to
>>>>>>>     tell that this routine was called first.

Mike Guy

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About