当前位置:首页 » Perl » Perl chomp()函数

Perl chomp()函数

perl chomp()函数,chomp()函数学习例子,chomp()函数实例代码,chomp()函数在线教程等

语法

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