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

Re: [ID 19991115.012] Localization and goto()

Thread Previous | Thread Next
From:
M.J.T. Guy
Date:
November 16, 1999 07:05
Subject:
Re: [ID 19991115.012] Localization and goto()
Message ID:
E11nkAM-0004dC-00@taurus.cus.cam.ac.uk
ilya@math.ohio-state.edu wrote
> $a = 5;
> 
> sub a { print $a }
> sub b {local $b = 9; goto &a}
               $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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About