perl-5.38.0
goto LABEL
goto EXPR
goto &NAME

The goto LABEL 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 sort. 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 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). (The difference is that C does not offer named loops combined with loop control. Perl does, and this replaces most structured uses of goto in other languages.)

goto LABEL の形式は、LABEL というラベルの付いた文を 探して、そこへ実行を移すものです。 sort で与えられたブロックやサブルーチンから外へ 出ることはできません。 これ以外は、サブルーチンの外を含む、動的スコープ内の ほとんどすべての場所へ行くために使用できますが、普通は、 lastdie といった別の構造を使った方が 良いでしょう。 Perl の作者はこの形式の goto を使う必要を感じたことは、 1 度もありません (Perl では; C は別のお話です)。 (違いは、C にはループ制御と結びついた名前つきのループがないことです。 Perl にはあり、これが他の言語でのほとんどの構造的な goto の 使用法を置き換えます。)

The goto EXPR form expects to evaluate EXPR to a code reference or a label name. If it evaluates to a code reference, it will be handled like goto &NAME, below. This is especially useful for implementing tail recursion via goto __SUB__.

goto EXPR の形式は、EXPR をコードリファレンスまたはラベル名として 評価することを想定します。 コードリファレンスとして評価する場合、後述する goto &NAME のように 扱います。 これは特に、goto __SUB__ による末尾再帰の実装に有用です。

If the expression evaluates to a label name, its scope will be resolved dynamically. This allows for computed gotos per FORTRAN, but isn't necessarily recommended if you're optimizing for maintainability:

式がラベル名に評価される場合、このスコープは動的に解決されます。 これにより FORTRAN のような算術 goto が可能になりますが、 保守性を重視するならお勧めしません。

    goto ("FOO", "BAR", "GLARCH")[$i];

As shown in this example, goto EXPR is exempt from the "looks like a function" rule. A pair of parentheses following it does not (necessarily) delimit its argument. goto("NE")."XT" is equivalent to goto NEXT. Also, unlike most named operators, this has the same precedence as assignment.

この例で示したように、goto EXPR は「関数のように見える」ルールから 除外されます。 これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。 goto("NE")."XT"goto NEXT と等価です。 また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。

Use of goto LABEL or goto EXPR to jump into a construct is deprecated and will issue a warning. Even then, it may not be used to go into any construct that requires initialization, such as a subroutine, a foreach loop, or a given 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 first parameter of a binary operator. (The = 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.

構造の中に飛び込むために goto LABELgoto EXPR を使うことは 非推奨で、警告が発生します。 それでも、サブルーチンや foreach ループや given ブロックのような、 初期化が必要な 構造の中に入るために使うことは出来ません。 一般的に、2 項演算子やリスト演算子の引数に飛び込むことはできませんが、 2 項演算子の 最初の 引数に飛び込むために使われていました。 (= 代入演算子の「最初の」オペランドはその右オペランドです。) また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。

The goto &NAME form is quite different from the other forms of goto. 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 local) and immediately calls in its place the named subroutine using the current value of @_. 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.

goto &NAME の形式は、その他の goto の形式とはかなり 異なったものです。 実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、 他の goto が持つ不名誉を持っていません。 現在のサブルーチンを終了し (local による変更は失われます)、 直ちに現在の @_ の値を使って指定された名前のサブルーチンを 呼び出します。 これは、AUTOLOAD サブルーチンが別のサブルーチンをロードして、 その別のサブルーチンが最初に呼ばれたようにするために使われます (ただし、現在のサブルーチンで @_ を修正した場合には、 その別のサブルーチンに伝えられます)。 goto のあとは、caller でさえも、現在の サブルーチンが最初に呼び出されたと言うことができません。

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.

NAME はサブルーチンの名前である必要はありません; コードリファレンスを 含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。