xxsr.net
当前位置:首页 >> pErl print 数组 >>

pErl print 数组

方法: my @array = (0, 1, 2, 3); print (“@array\n”); #输出有空格,如:0 1 2 3 print (@array, “\n”); #输出没空格,如:0123 哈希也可以用同样方法,如: my %hash = (); $hash{a} = ‘jeftom'; $hash{b} = ‘design'; print (%hash);

@data = qw/ 1 2 3 /; push @data, 5; #---数组后加5,@new = push @data, 5整个语句返回加过5后的元素个数即为4 print "@data\n"

#! /usr/bin/perl use strict; use warnings; my @array = (0 .. 9); my $tmp = 10; print "@array\n"; push(@array,$tmp); print "@array\n"; @array = $tmp + 1; print "@array\n"; ------------------------------------------------- 输出:...

sub choose(){ my (@c1, @c2, @c3); @c1 = @_; @c2 = sort @_; @c3 = reverse @_; return (\@c1,\@c2,\@c3); } my @arr = (1,2,3,5,4); my (@a,@b,@c); my @refs = &choose(@arr); @a = @{$refs[0]}; @b = @{$refs[1]}; @c = @{$refs[2]}; print...

首先来个基本函数参数的传递 sub hello { print "Hello @_" }hello ("World!", "I am Robot" ) ; # 打印出 Hello World! I am Robot这里值得留意的就是 @_ 就是装载所有传入的参数的数组 ( 看好了, 这其实是数组啊!! ) 所以, 将上面的改一下, 就...

sub randomElem { my ($want, @array) = @_ ; my (%seen, @ret); while ( @ret != $want ) { my $num = abs(int(rand($#array))); if ( ! $seen{$num} ) { ++$seen{$num}; push @ret, $array[$num]; } } return @ret; }my @array = ( 'A'..'Z' )...

示例: #!/usr/bin/perl -w use strict; my @array1 = (["a","b","c"],["d","e","f"],["g","h","i"]); my @array2 = (["a","b","c"],["d","e","f"]); &test (\@array1, \@array2); &test (\@array1, \@array2); sub test { my ($subarray1, $sub...

$" = "\n"; @arr = (1, 2, 3, 4, 5); open OUT, "> a.txt"; print OUT "@arr"; 数组内插时,分隔符默认$"的值,可以通过修改$"的值来修改如何分割

难道不是每次循环都清空@all吗(@all=();)?每次循环都清空一次,当然只有最后一次的结果了。

这个是没办法已经匹配存入新数组之后去获得的,不过可以尝试其他方式,代码修改为以下吧: for(my $i = 0; $i < @all_file; $i++){ if($all_file[$i]=~/$str/g){ print "Matched in line:$_,Index is:$i\n" } } 这样可以变相实现你的要求

网站首页 | 网站地图
All rights reserved Powered by www.xxsr.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com