谁能帮我改改错

谁能帮我改改错

谁能帮我改改错
#!/usr/bin/perl -w
use strict;
print << 'here';
小型服务器上的统计
here
my @line=split("\n",`netstat -n -a`);

my $count_1=0;
my $count_2=0;
my $count_3=0;
my $count_4=0;
my $count_5=0;
my $count_6=0;
my $count_7=0;
my $count_8=0;
my $num=scalar @line;
my $i;

foreach $i(1..$num){
if ($line[$i]=~/LISTENING/){
++$count_1;}
if ($line[$i]=~/ESTABLISHED/){
++$count_2;}
if ($line[$i]=~/CLOSE_WAIT/){
++$count_3;}
if ($line[$i]=~/TIME_WAIT/){
++$count_4;}
if ($line[$i]=~/FIN_WAIT_1/){
++$count_5;}
if ($line[$i]=~/FIN_WAIT_2/){
++$count_6;}
if ($line[$i]=~/LAST_ACK/){
++$count_7;}
if ($line[$i]=~/CLOSING/){
++$count_8;}
}
print "CLOSING","\t\t\t",$count_8,"\n";
print "TIME_WAIT","\t\t",$count_4,"\n";
print "CLOSE_WAIT","\t\t",$count_3,"\n";
print "LAST_ACK","\t\t",$count_7,"\n";
print "LISTENING","\t\t",$count_1,"\n";
print "FIN_WAIT_1","\t\t",$count_5,"\n";
print "FIN_WAIT_2","\t\t",$count_6,"\n";
print "LAST_ACK","\t\t",$count_7,"\n";
print "ESTABLISHED","\t\t",$count_2,"\n";

1;

#出现以下错误use of uninitialized value in pattern match
[CCB]10[/CCB]
thank you for your attention
比如一个数组有100个元素那么大,下标的范围就是0..99,而不是1..100,你
让循环在1..100上面走,走到下标100的时候perl就给警报了,因为下标100在
perl里面表示数组的第101个元素,而数组没那么大,得到的是未定义值,用
这个undef的值做正则表达式匹配,自然就错了。 ( By my lovely teacher.)[CCB]1[/CCB]