View Single Post
  #2 (permalink)  
Old 03-17-06, 04:08 AM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
one way:

Code:
use strict;
my %top_ten = ();
open(LOG,'<log.txt') or die "can't open log.txt: $!";
while(my $line = <LOG>){
   my ($ip) = $line =~ /^([^\s]+)/;
   $top_ten{$ip}++;
}
close(LOG);
my @top_list = map {"$_->[0] ($_->[1] requests)"}
               sort {$b->[1] <=> $a->[1]}
               map {[$_,$top_ten{$_}]} keys %top_ten;

for my $i (0..9) {
   print "@{[$i+1]}: $top_list[$i]\n";
}
Reply With Quote