- $OS_ERROR
- $ERRNO
- $!
-
When referenced,
$!retrieves the current value of the Cerrnointeger variable. If$!is assigned a numerical value, that value is stored inerrno. When referenced as a string,$!yields the system error string corresponding toerrno.参照されると、
$!は C のerrno整数変数の現在の値を取得します。$!に数値が代入されると、その値はerrnoに保管されます。 文字列として参照されると、$!はerrnoに対応するシステムエラー 文字列を返します。Many system or library calls set
errnoif they fail, to indicate the cause of failure. They usually do not seterrnoto zero if they succeed and may seterrnoto a non-zero value on success. This meanserrno, hence$!, is meaningful only immediately after a failure:多くのシステムやライブラリ呼び出しは、失敗したときに、失敗の理由を示すために
errnoを設定します。 これらは普通は成功したときにはerrnoにゼロを設定 しません; 成功時にはerrnoに非ゼロを設定するかもしれません。 これは、errno、$!は、失敗 の 直後 でのみ意味が あるということです:if (open my $fh, "<", $filename) { # Here $! is meaningless. ... } else { # ONLY here is $! meaningful. ... # Already here $! might be meaningless. } # Since here we might have either success or failure, # $! is meaningless.
if (open my $fh, "<", $filename) {
# ここで $! は無意味。
...
}
else {
# ここでだけ $! に意味がある。
...
# ここで既に $! は無意味かもしれません。
}
# ここでは成功と失敗の両方の可能性があるので、
# $! は無意味。
Here, meaningless means that $! may be unrelated to the outcome of the open() operator. Assignment to $! is similarly ephemeral. It can be used immediately before invoking the die() operator, to set the exit value, or to inspect the system error string corresponding to error n, or to restore $! to a meaningful state.
ここで、無意味 というのは $! は open() 演算子の結果に 関係ないということです。 $! への代入も同様に一時的なものです。 これは、終了値を設定したり、エラー n に対応するシステムエラー文字列を 調べたり、$! を意味のある状態に復元するために、die() 演算子を 起動する直前で使えます。
Perl itself may set errno to a non-zero on failure even if no system call is performed.
Perl 自身は、システムコールを実行しなくても失敗時には errno に非ゼロを設定するかもしれません。
Mnemonic: What just went bang?
記憶法: 何が bang(!) したか。