Perl chop()函数
Perl中的chop()函数用于删除输入字符串中的最后一个字符。
语法: chop(String)
参数:
String : 是指被删除最后一个字符的输入字符串。
返回: 最后删除的字符。
例子 1 :
#!/usr/bin/perl
# Initialising a string
string = "GfG is a computer science portal";
# Calling the chop() functionA = chop(string);
# Printing the chopped string and
# removed character
print " Chopped String is :string\n";
print " Removed character is : $A\n";
输出
Chopped String is : GfG is a computer science porta
Removed character is : l
例2:
#!/usr/bin/perl
# Initialising a string
string = "[1, 2, 3]";
# Calling the chop() functionA = chop(string);
# Printing the chopped string and
# removed character
print " Chopped String is :string\n";
print " Removed character is : $A\n";
输出:
Chopped String is : [1, 2, 3
Removed character is : ]