- 论坛徽章:
- 0
|
我也练习做了一个。散列的散列:
#!/usr/bin/perl
use strict;
my(%animal,$date,$station,$key);
format STDOUT_TOP =
Animal Id Station 1 Station 2
-----------------------------------------------
.
format STDOUT =
@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<@<<<<<<<<
$key $animal{$key}{s1} $animal{$key}{s2}
.
open F,"data.txt"||die "Can't open file: $!\n";
while (<F>){
chomp;
($key,$date,$station)=split/:/;
$animal{$key}{s1}++ if $station =~ /s1/;
$animal{$key}{s2}++ if $station =~ /s2/;
}
for $key (sort keys %animal){
$animal{$key}{s1}=0 unless defined $animal{$key}{s1};
$animal{$key}{s2}=0 unless defined $animal{$key}{s2};
write ;
#print "$key:\t$animal{$key}{s1}\t$animal{$key}{s2}\n";
} |
|