描述
此更安全的印章版本将删除任何与$/当前值相对应的结尾字符串(在英语模块中也称为$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
参考链接
https://www.learnfk.com/perl/perl-chomp.html
标签:String,无涯,chomp,Perl,characters,Number,print,string1 From: https://blog.51cto.com/u_14033984/6983520