这是另一种替换方式,语法如:tr/string1/string2/。同样,string2为替换部分,但其效果是把string1中的第一个字符替换为string2中的第一个字符,把string1中的第二个字符替换为string2中的第二个字符,依此类推。如: $string="abcdefghicba"; $string=~tr/abc/def/;#nowstring="defdefghifed" 当string1比st...
array:数组,列表,以@开头; Hash: 哈希,散列,以%开头 文件: 2、变量特征 大写字母 区分大小写:$Var,$VAR,$var 内置变量:$/,$@、@ARGV、$_等 3、字符串变量 由双引号或单引号标识的一组字符组成;最少0个字符(“”为空串),最多可以占满内存, "${str}ing"=$str +ing" !=$string 记住一些常用的...
这是另一种替换方式,语法如:tr/string1/string2/。同样,string2为替换部分,但其效果是把string1中的第一个字符替换为string2中的第一个字符,把string1中的第二个字符替换为string2中的第二个字符,依此类推。如: $string=”abcdefghicba”; $string=~tr/abc/def/;#nowstring=”defdefghifed” 当string1...
@subarray = @array[0,1]; # @subarray = (1, 2) @subarray2 = @array[1..3]; # @subarray2 = (2,3,4) @array[0,1] = ("string", 46); # @array =("string",46,3,4,5) now @array[0..3] = (11, 22, 33, 44); # @array = (11,22,33,44,5) now @array[1,2,3] ...
if ($string =~ /[a-z]/) { print "The string contains a lowercase letter.\n"; } 这个正则表达式会匹配任何小写字母。 单引号('') 在Perl中,单引号用于创建字符串字面量,其中的特殊字符不会被解释。例如: 代码语言:txt 复制 my $regex = '/[aeiou]/'; if ($string =~ $regex) { print "...
print "$array[$i]\n"; } 看到$#array这个奇怪的东东没? 这是Perl的一个特殊用法,代表这个数组最后一个元素的注标。由于Perl不必事先宣告变量,也不必预先宣告数组的大小,甚至可以随时增加新元素,那我们怎么知道这个数组到底有多大呢? 透过这个特殊变量我们可以得知这个这个数组最后一个元素的注标,自然而然也就知...
First, Usefor loopto iterate an array, and$_contains the temporary variable to hold iterated element, Check current element matches the given element using the if conditional statement. prints a string to the console. Here is an example
@array = split (/ +/, $line); 注:split函数每次遇到分割模式,总是开始一个新单词,因此若$line以空格打头,则@array的第一个元素即为空元素。但其可以区分是否真有单词,如若$line中只有空格,则@array则为空数组。且上例中TAB字符被当作一个单词。注意修正。
–`split /pattern/, $string` – Split a string into an array based on a pattern. Regular expressions can be used to perform complex string manipulations and data processing tasks. 6. System and process interaction with Perl: Perl provides various commands for interacting with the Linux system ...
In addition, Perl containsqandqqoperators to define strings. Perl contains many built-in functions to work with strings, such aslength,uc,lc, orsubstr. Also, there are third-party modules for working with strings; e.g.String::Util.