perl 引用/hash
来源:互联网 发布:正品良心淘宝日本代购 编辑:程序博客网 时间:2024/05/19 18:43
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","2","3","4"};@list=("1","2","3","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 style="font-size:14px;">#!/opt/exp/bin/perl -w#it doesn't use $_ in hash and array#array#set value@list = (4,3,2,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是一个执行
0 0
- perl 引用/hash
- perl 引用(数组和hash引用)
- [Perl]用hash引用时别忘了初始化
- Perl 使用引用来访问hash 数组
- 在Perl里 对象就是hash引用
- Perl (hash)
- perl hash
- perl hash
- perl hash
- perl hash
- 简述perl的引用(包括标量、数组、hash等数据类型的引用)
- perl引用
- Perl引用
- perl 引用
- perl 引用
- perl 引用
- perl hash operate
- perl-hash的用法
- 四大组件之BroadcastReceiver
- Linux的Init程序与系统服务管理
- Hadoop Exception: java.lang.IllegalArgumentException: Does not contain a valid host:port authority:
- minicom & runscript 介绍
- NSUserDefaults存储mutable类型实例
- perl 引用/hash
- javascript (function(){})()
- 学校如何创建网站?
- window.location.href的用法
- PHP静态变量初始化一次
- 在工具栏上添加下拉箭头按钮
- BAE上搭建flask环境
- apache kafka系列之jmx监控指标参数
- TCP状态转换图