chomp VARIABLE chomp( LIST ) chomp |
这更安全的版本的印章删除任何尾随的字符串,对应的当前值$/(也称为$ INPUT_RECORD_SEPARATOR在英文模块)。它返回的总数从它的所有参数的字符。默认情况下$/设置为新行字符。
整数,所有字符串中删除的字节数
#!/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 ); #by www.gitbook.net 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