Perl Chop函式



說明

此函式從EXPR中移除最後一個字元,從LIST的每個元素中移除,如果沒有指定值則移除$_。

語法

以下是此函式的簡單語法−

chop VARIABLE

chop( LIST )

chop

返回值

此函式返回從EXPR中移除的字元,並且在列表上下文中,從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
perl_function_references.htm
廣告
© . All rights reserved.