goto 
gotoLABELgotoEXPRgoto &NAME
goto
LABEL finds the statement labelled with
LABEL and resumes execution there. If the
LABEL cannot be found, an exception is
raised. It cannot be used to go into any construct that requires
initialization, such as a subroutine or a foreach loop. It also can’t be used to go into
a construct that is optimized away. It can be used to go almost anywhere
else within the dynamic scope,[237] including out of subroutines; however, for that purpose,
it’s usually better to use some other construct such as last or die. The author of Perl has never felt the
need to use this form of goto (in
Perl, that is—C is another matter).
Going to even greater heights of orthogonality (and depths of
idiocy), Perl allows goto
EXPR, which expects
EXPR to evaluate to a label name, whose
location is guaranteed to be unresolvable until
runtime since the label is unknown when the statement is compiled. This
allows for computed gotos per
FORTRAN, but isn’t recommended if you’re optimizing for
maintainability:
goto +("FOO", "BAR", "GLARCH")[$i];The unrelated goto &NAME is highly
magical, substituting a call to the named subroutine for the currently
running subroutine. This construct may be used without shame by AUTOLOAD subroutines that wish to load another subroutine and then pretend that this new subroutine—and not the original one—had been called in the first place (except that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access