- oct EXPR
- oct
-
Interprets EXPR as an octal string and returns the corresponding value. An octal string consists of octal digits and, as of Perl 5.33.5, an optional
0ooroprefix. Each octal digit may be preceded by a single underscore, which will be ignored. (If EXPR happens to start off with0xorx, interprets it as a hex string. If EXPR starts off with0borb, it is interpreted as a binary string. Leading whitespace is ignored in all three cases.) The following will handle decimal, binary, octal, and hex in standard Perl notation:EXPR を 8 進数文字列と解釈して、対応する値を返します。 8 進数文字列は、8 進文字と、Perl 5.33.5 からはオプションの
0oまたはo接頭辞からなります。 各 8 進文字の前には一つの下線を置くことができ、これは無視されます。 (EXPR が0xかxで始まるときには、16 進数文字列と解釈します。 EXPR が0bかbで始まるときは、2 進数文字列と解釈します。 どの場合でも、先頭の空白は無視されます。) 以下の例は、標準的な Perl の記法での 10 進数、2 進数、8 進数、16 進数を扱います:$val = oct($val) if $val =~ /^0/;If EXPR is omitted, uses
$_. To go the other way (produce a number in octal), use sprintf or printf:EXPR が省略されると、
$_を使います。 (8 進数を扱う)その他の方法をとしては sprintf や printf があります:my $dec_perms = (stat("filename"))[2] & 07777; my $oct_perm_str = sprintf "%o", $perms;The
octfunction is commonly used when a string such as644needs to be converted into a file mode, for example. Although Perl automatically converts strings into numbers as needed, this automatic conversion assumes base 10.oct関数は例えば、644といった文字列をファイルモードに 変換する時によく使います。 Perl は必要に応じて自動的に文字列を数値に変換しますが、 この自動変換は十進数を仮定します。Leading white space is ignored without warning, as too are any trailing non-digits, such as a decimal point (
octonly handles non-negative integers, not negative integers or floating point).先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます (
octは非負整数のみを扱えます; 負の整数や小数は扱えません)。