Я написал код для определения количества IP-адресов из текстового файла. если в файле toto.txt есть похожие IP-платья:
Мой код для этого:
use strict;
use warnings;
my %count;
my $str ;
#my $file = shift or die "Usage: $0 FILE\n";
my $address = "192.168.2.16";
 open my $fh, '<', 'C:\shekhar_Axestrack_Intern\WindowCreation\toto.txt', or die "Could not open file $!";
 print "address is $address \n";
while (my $line = <$fh>) 
{
    chomp $line;
    foreach my $str ($address, $line) 
    {
        $count{$str}++;
    }   
}
foreach $str (sort keys %count) 
{
    printf "%s\n", $count{$str};
}
close $fh;
Я ожидаю, что это вернет 4 счетчика, потому что в списке toto.txt 4 таких адреса.
Address is : 100.64.26.172  and the Time is : Thu Jan 15 18:11:31 2015 End
Address is : 192.168.2.16  and the Time is : Thu Jan 15 18:12:33 2015 End
Address is : 100.65.15.169  and the Time is : Thu Jan 15 18:13:51 2015 End
Address is : 192.168.2.16  and the Time is : Thu Jan 15 18:15:17 2015 End
Address is : 100.65.34.233  and the Time is : Thu Jan 15 18:18:04 2015 End
Address is : 192.168.2.16  and the Time is : Thu Jan 15 18:19:46 2015 End
Address is : 100.64.8.194  and the Time is : Thu Jan 15 18:31:58 2015 End
Address is : 192.168.2.16  and the Time is : Thu Jan 15 18:33:30 2015 End
Но вывод таков:
address is 192.168.2.16
8
1
1
1
1
1
1
1
1
Как изменить мой код, чтобы получить 4 IP-адреса (что на самом деле 4)?
