perl-5.38.0
chomp VARIABLE
chomp( LIST )
chomp

This safer version of chop removes any trailing string that corresponds to the current value of $/ (also known as $INPUT_RECORD_SEPARATOR in the English module). It returns the total number of characters removed from all its arguments. It's often used to remove the newline from the end of an input record when you're worried that the final record may be missing its newline. When in paragraph mode ($/ = ''), it removes all trailing newlines from the string. When in slurp mode ($/ = undef) or fixed-length record mode ($/ is a reference to an integer or the like; see perlvar), chomp won't remove anything. If VARIABLE is omitted, it chomps $_. Example:

より安全な chop (以下を参照してください) です; $/ (English モジュールでは、 $INPUT_RECORD_SEPARATOR とも言う) のその時点の 値に対応する行末文字を削除します。 全ての引数から削除した文字数の合計を返します。 入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が 入っているのかわからないような場合に、使用できます。 段落モード ($/ = '') では、レコードの最後の改行をすべて取り除きます。 吸い込みモード ($/ = undef) や 固定長レコードモード ($/ が整数へのリファレンスや類似のものの場合; perlvarを参照してください)では、chomp は 何も取り除きません。 VARIABLE が省略されると、$_ を対象として chomp します。 例:

    while (<>) {
        chomp;  # avoid \n on last field
        my @array = split(/:/);
        # ...
    }

If VARIABLE is a hash, it chomps the hash's values, but not its keys, resetting the each iterator in the process.

VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し、 このプロセスの each 反復子をリセットします。

You can actually chomp anything that's an lvalue, including an assignment:

左辺値であれば、代入を含めて、任意のものを chomp できます:

    chomp(my $cwd = `pwd`);
    chomp(my $answer = <STDIN>);

If you chomp a list, each element is chomped, and the total number of characters removed is returned.

リストを chomp すると、個々の要素が chomp され、 削除された文字数の合計が返されます。

Note that parentheses are necessary when you're chomping anything that is not a simple variable. This is because chomp $cwd = `pwd`; is interpreted as (chomp $cwd) = `pwd`;, rather than as chomp( $cwd = `pwd` ) which you might expect. Similarly, chomp $a, $b is interpreted as chomp($a), $b rather than as chomp($a, $b).

単純な変数以外のものを chomp する場合はかっこが必要であることに 注意してください。 これは、chomp $cwd = `pwd`; は、予測している chomp( $cwd = `pwd` ) ではなく、(chomp $cwd) = `pwd`; と 解釈されるからです。 同様に、chomp $a, $bchomp($a, $b) ではなく chomp($a), $b と解釈されます。