
1
#!/opt/exp/bin/perl -w#array init@a=();@Lol=();sub function { $j=@_; @a=("1","2","3"); print "j=$j\n"; 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 -wsub 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 -wmy @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 hashprint "%$ref\n"; print "$$ref{abc}\n";4 <span >#!/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->$item\n",$i++)}#hashwhile (my ($key,$value) = each (%ENV)) { print "$key - $value\n";}my @val =sort keys %ENV;for ($i=0;$i<@val;$i++) { $key=$val[$i]; print "$key-----$ENV{$key} \n";}</span> ==
在将hash的keys sort 后,sort是一个独立的循环 *** 作.先这个函数。
map是一个独立的循环,输出key和value,
即按比较顺序输出key-value
print map {"$_ -> $hash{$_}"} sort {$a cmp $b} keys %hash; 应该是print if aa ; 这种单句处理 上面的sort是一个执行
总结以上是内存溢出为你收集整理的perl 引用/hash全部内容,希望文章能够帮你解决perl 引用/hash所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)