目录

chomp

描述 (Description)

这个更安全的chop版本删除了与$ /的当前值相对应的任何尾随字符串(在英语模块中也称为$ INPUT_RECORD_SEPARATOR)。 它返回从其所有参数中删除的字符总数。 默认情况下,$ /设置为换行符。

语法 (Syntax)

以下是此函数的简单语法 -

chomp VARIABLE
chomp( LIST )
chomp

返回值 (Return Value)

此函数返回Integer,为所有字符串删除的字节数。

例子 (Example)

以下是显示其基本用法的示例代码 -

#!/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
↑回到顶部↑
WIKI教程 @2018