in reply to Perl 5.12.0 has been released!

Use of "goto" to jump into a construct
Using goto to jump from an outer scope into an inner scope is now deprecated. This rare use case was causing problems in the implementation of scopes.
Does this include Magic goto in relation to AUTOLOAD?

Replies are listed 'Best First'.
Re^2: Perl 5.12.0 has been released!
by Corion (Patriarch) on Apr 15, 2010 at 07:35 UTC

    I think not, as with AUTOLOAD, you mostly leave the current scope and enter the scope of the target subroutine:

    use strict; use Carp qw(croak); use vars qw($AUTOLOAD); my %handler = ( hello => sub { print "Hello World\n" }, ); sub AUTOLOAD { (my $fn = $AUTOLOAD) =~ s/.*:://g; if (exists $handler{ $fn }) { goto &{ $handler{ $fn } } }; croak "Unknown method '$AUTOLOAD' called."; }; hello();

    In the above example, we only leave enclosed scopes and don't goto into an inner scope. Potentially (but I can't test this currently, due to lack of a 5.12), the following could fall under "goto into an inner scope", but I think it's not really into in this case:

    use strict; use Carp qw(croak); use vars qw($AUTOLOAD); sub AUTOLOAD { (my $fn = $AUTOLOAD) =~ s/.*:://g; my %handler = ( hello => sub { print "Hello World\n" }, ); if (exists $handler{ $fn }) { goto &{ $handler{ $fn } } }; croak "Unknown method '$AUTOLOAD' called."; }; hello();

    Here, the handlers are arguably in an inner scope, relative to AUTOLOAD. But what I think the change note really means is that jumping "into (the middle of) an inner scope" is deprecated:

    START: goto INSIDE; OUTSIDE: if (0) { INSIDE: print "Hello "; INSIDE2: print "World\n"; };

    Here, I think the labels INSIDE and INSIDE2 are not reachable from START (or rather, reaching them is deprecated with 5.12), while OUTSIDE is reachable.

    AUTOLOAD subroutines are not affected by that, unless you goto into the body of such a subroutine by holding onto a label within that subroutine, but that's not related to AUTOLOAD:

    my $handler = sub { INSIDE: print "Hello "; INSIDE2: print "World\n"; }; goto INSIDE; # deprecated goto INSIDE2; # deprecated goto &$handler; # still works, as we start "just on the outside" of $h +andler
Re^2: Perl 5.12.0 has been released!
by ikegami (Patriarch) on Apr 15, 2010 at 18:02 UTC

    goto &$f doesn't do any jumping at all. It's unrelated and thus unaffected.

    $ perl5.12.0 -E'sub g { say "g" } sub f { goto &{ \&g } } f();' g

    It's stuff like this:

    $ perl5.12.0 -e'goto FOO; while (1) { FOO: last }' Use of "goto" to jump into a construct is deprecated at -e line 1.

    Jumping out is fine.

    $ perl5.12.0 -E'while (1) { goto FOO; } FOO: say "done"' done