无涯教程-Perl - chop函数

60 阅读1分钟

描述

此函数从EXPR,LIST的每个元素或$_(如果未指定值)中删除最后一个字符。

语法

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

chop VARIABLE

chop( LIST )

chop

返回值

此函数返回从EXPR中删除的字符,并且在列表context中,从LIST的最后一个元素中删除该字符。

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

#!/usr/bin/perl

$string1="This is test";
$retval =chop( $string1 );

print " Choped String is : $string1\n";
print " Character removed : $retval\n";

执行上述代码后,将产生以下输出-

Choped String is : This is tes
Number of characters removed : t

参考链接

www.learnfk.com/perl/perl-c…