perl-5.38.0
exit EXPR
exit

Evaluates EXPR and exits immediately with that value. Example:

EXPR を評価し、即座にその値を持って終了します。 例:

    my $ans = <STDIN>;
    exit 0 if $ans =~ /^[Xx]/;

See also die. If EXPR is omitted, exits with 0 status. The only universally recognized values for EXPR are 0 for success and 1 for error; other values are subject to interpretation depending on the environment in which the Perl program is running. For example, exiting 69 (EX_UNAVAILABLE) from a sendmail incoming-mail filter will cause the mailer to return the item undelivered, but that's not true everywhere.

die も参照してください。 EXPR が省略された場合には、ステータスを 0 として終了します。 EXPR の値として広く利用可能なのは 0 が成功で 1 が エラーということだけです; その他の値は、 Perl が実行される環境によって異なる 解釈がされる可能性があります。 例えば、sendmail 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると メーラーはアイテムを配達せずに差し戻しますが、 これはいつでも真ではありません。

Don't use exit to abort a subroutine if there's any chance that someone might want to trap whatever error happened. Use die instead, which can be trapped by an eval.

誰かが発生したエラーをトラップしようと考えている可能性がある場合は、 サブルーチンの中断に exit を使わないでください。 代わりに eval でトラップできる die を 使ってください。

The exit function does not always exit immediately. It calls any defined END routines first, but these END routines may not themselves abort the exit. Likewise any object destructors that need to be called are called before the real exit. END routines and destructors can change the exit status by modifying $?. If this is a problem, you can call POSIX::_exit($status) to avoid END and destructor processing. See perlmod for details.

exit 関数は常に直ちに終了するわけではありません。 まず、定義されている END ルーチンを呼び出しますが、 END ルーチン自身は exit を止められません。 同様に、呼び出す必要のあるオブジェクトデストラクタは すべて、実際の終了前に呼び出されます。 END ルーチンとデストラクタは $? を修正することで 終了コードを変更できます。 これが問題になる場合は、END やデストラクタが実行されることを 防ぐために POSIX::_exit($status) を呼び出してください。 詳しくは perlmod を参照してください。

Portability issues: "exit" in perlport.

移植性の問題: "exit" in perlport