此更安全的印章版本将删除任何与$/当前值相对应的结尾字符串(在英语模块中也称为$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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)