Perl-chomp
提供:Dev Guides
Perl chomp関数
説明
この安全なバージョンのchopは、現在の値$/(英語モジュールでは$ INPUT_RECORD_SEPARATORとも呼ばれます)に対応する後続文字列を削除します。 すべての引数から削除された文字の総数を返します。 デフォルトでは、$/は改行文字に設定されます。
構文
以下は、この関数の簡単な構文です-
chomp VARIABLE
chomp( LIST )
chomp
戻り値
この関数は、すべての文字列から削除されたバイト数の整数を返します。
例
以下は、その基本的な使用法を示すコード例です-
#!/usr/bin/perl
$string1 = "This is test";
$retval = chomp( $string1 );
print " Choped String is : $string1\n";
print " Number of characters removed : $retval\n";
$string1 = "This is test\n";
$retval = chomp( $string1 );
print " Choped String is : $string1\n";
print " Number of characters removed : $retval\n";
上記のコードが実行されると、次の結果が生成されます-
Choped String is : This is test
Number of characters removed : 0
Choped String is : This is test
Number of characters removed : 1