JupiterHost.Net wrote:
Instead of createing a new file that has each fuile in it (doubling the space and memeory used) process them one ata time:
my %ipbytes = ();
for my $file(@logfiles) {
open LOG, $file or die $1;
while(<LOG>) {
my ($ip,$bytes) = split /\:/, $_; # or however you get the ip and bytes from a line
$ipbytes{$ip} += $bytes; # may want top make sure $bytes is numeric to avoid possible errors
}
close LOG;
}
Hi,
i should have include my code in the beginning, because i've done this already. I know that in this case a hash is generated for every file. But when i do the printing outside the foreach-loop just the hash of the last file is printed. I'm aware about that problem but could not figure out how to create only one hash for all files.
Thanks
Folker Naumann
---------------------------------------------------------- (...) foreach $file (@sortlist){
open(LOG,$file) or die "Can't open $file: $!\n"; @lines = <LOG>; foreach my $logline (reverse(@lines)) {
#Search for Host-IP-Adress and bytes if( $logline =~ / (\d+\.\d+\.\d+\.\d+) \w*\/\w* (\d+) [A-Z]+/ ){ if($ipload{$1}) {$ipload{$1}+=$2} else {$ipload{$1}=$2} } }
#Close log file close(LOG) or die "Can't close $file: $!\n";
#Print hash sorted by Host-IP-Adress
foreach $ip ( map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, (/(\d+)$/)[0] ] } keys %ipload) {
print "$ip = $ipload{$ip}\n";
}
----------------------------------------------------------
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>