tekkie has asked for the wisdom of the Perl Monks concerning the following question:
For those interested, the code is used to extract source/destination IP pairs from logs we use at the office...my ($cap, %dest); # Open a file and slurp in the entire contents to one scalar open(CAP, "$file"); while(<CAP>) { $cap .= $_; } close CAP; # Scan through the contents for source/dest pairs and keep track of ho +w many times the dest gets hit: while($cap =~ /\s+(?:(?:\d{1,3}\.){3}\d{1,3})\s+->(\d{1,3}\.){3}\d{1,3 +})\s+/g) { unless(exists($dest{$1})) { $dest{$1} = 1; } else { $dest{$1}++; } } # Print out the destinations and the number of times they were hit in +descending order foreach my $dest_addr (sort { $dest{$b} <=> $dest{$a} } keys %dest) { print "$dest_addr\t$dest{$dest_addr}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Same code, same data, different execution times?
by dws (Chancellor) on Mar 19, 2003 at 23:37 UTC | |
|
Re: Same code, same data, different execution times?
by Abigail-II (Bishop) on Mar 19, 2003 at 23:09 UTC | |
|
Re: Same code, same data, different execution times?
by graff (Chancellor) on Mar 20, 2003 at 02:42 UTC | |
by Anonymous Monk on Mar 21, 2003 at 18:00 UTC | |
by Anonymous Monk on Mar 21, 2003 at 18:38 UTC | |
|
Re: Same code, same data, different execution times?
by tekkie (Beadle) on Mar 20, 2003 at 12:52 UTC | |
|
Re: Same code, same data, different execution times?
by dga (Hermit) on Mar 19, 2003 at 22:17 UTC | |
|
Re: Same code, same data, different execution times?
by dga (Hermit) on Mar 19, 2003 at 22:20 UTC | |
|
Re: Same code, same data, different execution times?
by traveler (Parson) on Mar 19, 2003 at 23:29 UTC |