发布时间:2025-12-09 11:59:11 浏览次数:2
这个更安全的chop版本删除了与$/(在英语模块中也称为$INPUT_RECORD_SEPARATOR)的当前值相对应的任何尾随字符串。它返回从其所有参数中删除的字符总数。默认情况下 $/设置为换行符。
以下是此函数的简单语法 âˆ'
chomp VARIABLEchomp( 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 testNumber of characters removed:0Choped String is:This is testNumber of characters removed:1