[root@june3 ~]# cat a2.pl
%log;
foreach (1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,5,6) {
print "$log{$_} is $log{$_}
";
$log{$_}++;
};
while(my($ip, $times) = each %log) {
print "$ip $times
";
}
[root@june3 ~]# perl a2.pl
$log{1} is
$log{1} is 1
$log{1} is 2
$log{2} is
$log{2} is 1
$log{2} is 2
$log{2} is 3
$log{2} is 4
$log{2} is 5
$log{3} is
$log{3} is 1
$log{3} is 2
$log{3} is 3
$log{3} is 4
$log{3} is 5
$log{4} is
$log{5} is
$log{6} is
6 1
4 1
1 3
3 6
2 6
5 1
##使用hash数组
my %hash=("1","HOST",
"2","FILESYSTEM",
"3","TYPE",
"4","SIZE#",
"5","USED",
"6","AVAIL",
"7","USE",
"8","MOUNTED",
"9","SYSDATE");
foreach $key (sort keys %hash)
{ my $var = $hash{$key};
print "$var is $var
";
my $tmp_label = $table->Label(-text => $var, -width => 20, -relief =>'raised');
##放到第0行 第N列
$table->put(0, $key, $tmp_label);
}