hi,lists, I have a file which is so large,which looking as:
61.156.49.18:28360 61.183.148.130:27433 222.90.207.251:25700 202.117.64.161:25054 218.58.59.73:24866 221.233.24.9:22507 222.187.124.4:21016 ... and more than 45000000 lines. the part after ":" is no use for me,I only need the IP. for each IP,such as '218.58.59.73', I want to get this result: 218.58.59. xxx yyy xxx+yyy I want to know how many IP are in the range of '218.58.59.1' to ' 218.58.59.127',this is 'xxx'; and how many IP are in the range of '218.58.59.128' to '218.58.59.254',this is 'yyy'. I write this code: open (FILE,$file) or die "$!"; while(<FILE>) { next if /unknown/o; next if /^192\.168\./o; chomp; my ($ip,$num) = split/:/,$_; if ($ip = ~ /^(\d+\.\d+\.\d+\.)(\d+)/o){ my ($net,$bit) = ($1,$2); $total{$net}{low}{$bit} = 1 if $bit < 128; $total{$net}{high}{$bit} = 1 if $bit >=128 and $bit < 255; $total{$net}{total}{$bit} = 1; } } close FILE; foreach (sort { scalar keys %{$total{$b}{total}} <=> scalar keys %{$total{$a}{total}} } keys %total) { print RESULT "$_","\t",scalar keys %{$total{$_}{low}},"\t", scalar keys %{$total{$_}{high}},"\t",scalar keys %{$total{$_}{total}},"\n"; } but it's too slow for me to wait the result.How can I get it more effective and run less time?thanks.