这样也可以,呵呵作者: liyangole 时间: 2010-10-21 16:07
我也练习做了一个。散列的散列:
#!/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){