";print"$str\n";# This is case of non-interpolation.$str ='Welcome to \niowiki.com!';print"$str\n";# Only W will become upper case.$str ="\uwelcome to iowiki.com!";print"$str\n";# Whole line will become capital.$str ="\UWelcome to iowiki.com!";print"$str\n";# A po...
# add one element at the beginning of the array unshift(@coins, "Dollar"); print "3.\@coins =@coins\n"; # remove one element from the last of the array. pop(@coins); print "4.\@coins =@coins\n"; # remove one element from the beginning of the array. shift(@coins); print "...
$scalar=@array;#$scalar=3,即@array的长度 ($scalar)=@array;#$scalar=1,即@array第一个元素的值 注:以Perl数组的长度为循环次数可如下编程: $count=1; while($count<=@array){ print("element$count:$array[$count-1]\n"); $count++; } 1. 2. 3. 4. 5. 6. 7. 8. 9. 6、子Perl数组...
匿名数组使用[]创建,匿名散列由{}创建: # 匿名数组 my $array_ref = ['one', 'two']; # 匿名散列 my $hash_ref = { one => '1', two => '2', }; 由于匿名散列与代码块有冲突,因此我们可以在左括号前加入一个+来显示的告诉Perl这是一个匿名散列,在左括号后面加入一个;来显示表示是一个代码...
#!/usr/bin/perl # create a simple array @coins = ("Quarter","Dime","Nickel"); print "1. \@coins = @coins\n"; # add one element at the end of the array push(@coins, "Penny"); print "2. \@coins = @coins\n"; # add one element at the beginning of the array unshift(@...
pop- remove the last element from an array and return it pos- find or set the offset for the last/next m//g search print- output a list to a filehandle printf- output a formatted list to a filehandle prototype- get the prototype (if any) of a subroutine ...
Note the fist parameter of push() and the only parameter of pop() must be an array. shift() & unshift() Shift() removes the first element out of an array, unshift() adds elements to the beginning of an array. @array=qw#dino fred barney#; ...
print $F[0] + $F[-2]; # offset -2 means "2nd to last element of the array" } 另一个常见任务是打印两个标记之间或两个行号之间的文件内容。 清单3:打印一系列行 # 1. just lines 15 to 17 perl -ne 'print if 15 .. 17'
Note that since "undef" is a valid scalar, its presence doesn't necessarily indicate an exceptional condition: "pop" returns "undef" when its argument is an empty array, or when the element to return happens to be "undef". You may also use "defined(&func)" to check whether perl v...
%s argument is not a HASH element or slice (F) The argument to delete() must be either a hash element, such as $foo{$bar} $ref->[12]->{"susie"} or a hash slice, such as @foo{$bar, $baz, $xyzzy} @{$ref->[12]}{"susie", "queue"} Allocation too large: %lx (X) You...