perl 引用/hash
发布时间:2020-12-15 23:56:21 所属栏目:大数据 来源:网络整理
导读:1? #!/opt/exp/bin/perl -w#array init@a=();@LoL=();sub function { $j=@_; @a=("1","2","3"); print "j=$jn"; return @a; }for $i (1..10) { @list = function ($i); #below two is the same,it is array reference $LoL[$i] = @list;# it is the same w
1? #!/opt/exp/bin/perl -w #array init @a=(); @LoL=(); sub function { $j=@_; @a=("1","2","3"); print "j=$jn"; return @a; } for $i (1..10) { @list = function ($i); #below two is the same,it is array reference $LoL[$i] = @list; # it is the same with above code # $LoL[$i] = [ @list ]; # it is array number $LoL[$i] = scalar @list; #notes add {},reback to array print "2:@{$LoL[$i]} n"; #print "2:$LoL[$i] n"; } 2: #!/opt/exp/bin/perl -w sub printSorted { ·#parameter1 is reference for array,parameter2 is hash.@_ list assign my ($data,%options) = @_; # get the value for array print "$data->[3]n"; #get hash value print "$options{type}n"; } #$list={"1","3","4"}; @list=("1","4"); printSorted (@list,dir => 'asc',type => 'numerical'); 3 #!/opt/exp/bin/perl -w my @array1 = (10,20,30,40,50); my @array2 = ( 1,2,@array1,3,4); %hash=(abc=>123,def=>456); #reference to hash $ref=%hash; #point to hash print "%$refn"; print "$$ref{abc}n";4 <span style="font-size:14px;">#!/opt/exp/bin/perl -w #it doesn't use $_ in hash and array #array #set value @list = (4,1,0); foreach $item (@list) { printf ("%d->$itemn",$i++) } #hash while (my ($key,$value) = each (%ENV)) { print "$key - $valuen"; } my @val =sort keys %ENV; for ($i=0;$i<@val;$i++) { $key=$val[$i]; print "$key-----$ENV{$key} n"; }</span> == print map {"$_ -> $hash{$_}"} sort {$a cmp $b} keys %hash;? 应该是print if aa ; 这种单句处理 上面的sort是一个执行 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |