CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/plain;charset=UTF-8
content-encoding: gzip
content-security-policy: default-src 'self'; connect-src 'self' *.google-analytics.com; img-src 'self' data: www.google-analytics.com www.googletagmanager.com; script-src 'self' 'unsafe-inline' www.google-analytics.com www.googletagmanager.com; style-src 'self'; report-uri /csp-reports
accept-ranges: bytes
age: 0
date: Thu, 31 Jul 2025 11:20:11 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210025-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753960811.633785,VS0,VE818
vary: Accept-Encoding
strict-transport-security: max-age=31557600
content-length: 1538
=over
=item goto LABEL
X X X
=item goto EXPR
=item goto &NAME
C transfers execution to a specified point in the program. Unlike a
function call, execution does not return to C.
The C form finds the statement labeled with LABEL and
resumes execution there. It can't be used to get out of a block or
subroutine given to L|/sort SUBNAME LIST>. It can be used to go
almost anywhere else within the dynamic scope, including out of
subroutines, but it's usually better to use some other construct such as
L|/last LABEL> or L|/die LIST>. The author of Perl has
never felt the need to use this form of C (in Perl,
that is; C is another matter). (The difference is that C does not offer
named loops combined with loop control. Perl does, and this replaces
most structured uses of C in other languages.)
The C form expects to evaluate C to a code reference or
a label name. If it evaluates to a code reference, it will be handled
like C, below. This is especially useful for implementing
tail recursion via C.
If the expression evaluates to a label name, its scope will be resolved
dynamically. This allows for computed Cs per
FORTRAN, but isn't necessarily recommended if you're optimizing for
maintainability:
goto ("FOO", "BAR", "GLARCH")[$i];
As shown in this example, C is exempt from the "looks like a
function" rule. A pair of parentheses following it does not (necessarily)
delimit its argument. C is equivalent to C.
Also, unlike most named operators, this has the same precedence as
assignment.
Use of C or C to jump into a construct is
deprecated and will issue a warning; it will become a fatal error in
Perl 5.42. While still available, it may not be used to
go into any construct that requires initialization, such as a
subroutine, a C loop, or a C
block. In general, it may not be used to jump into the parameter
of a binary or list operator, but it may be used to jump into the
I parameter of a binary operator. (The C<=>
assignment operator's "first" operand is its right-hand
operand.) It also can't be used to go into a
construct that is optimized away.
The C form is quite different from the other forms of
C. In fact, it isn't a goto in the normal sense at
all, and doesn't have the stigma associated with other gotos. Instead,
it exits the current subroutine (losing any changes set by
L|/local EXPR>) and immediately calls in its place the named
subroutine using the current value of L|perlvar/@_>. This is used
by C 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 L|perlvar/@_> in the current
subroutine are propagated to the other subroutine.) After the
C, not even L|/caller EXPR> will be able
to tell that this routine was called first.
NAME needn't be the name of a subroutine; it can be a scalar variable
containing a code reference or a block that evaluates to a code
reference.
=back