- 论坛徽章:
- 0
|
回复 43# zhlong8
求教高手,问什么下面生成的data.pl 里面总是有乱码,,,,,,疯了。
#!/urs/bin/perl -w
use strict;
use Storable;
my %total_bytes;
my $all = "all machines";
my $data_file = "data.pl";
if ( -e $data_file ) {
my $data = retrieve '$data_file';
%total_bytes = %$data;
}
open my $fh, '<', 'coconet.dat' or die $!;
while (<$fh>) {
next if (/^#/);
my ( $source, $destination, $bytes ) = split / /;
$total_bytes{$source}{$destination} += $bytes;
$total_bytes{$source}{$all} += $bytes;
}
store [ \%total_bytes ], $data_file;
my @sources =
sort { $total_bytes{$b}{$all} <=> $total_bytes{$a}{$all} }
keys %total_bytes; # sort houmian {}
for my $source (@sources) {
my @destinations =
sort { $total_bytes{$source}{$b} <=> $total_bytes{$source}{$a} }
keys %{ $total_bytes{$source} };
print "$source: $total_bytes{$source}{$all}\n";
for my $destination (@destinations) {
next if $destination eq $all;
print "$source=>$destination",
" transferred bytes is $total_bytes{$source}{$destination} bytes\n";
}
print "\n";
}
close $fh; |
|