Re: getting one hash out of multiple files

2004-10-07 Thread John W. Krahn
Folker Naumann wrote: Hi there! Hello, I'm fairly new to Perl and need some help to acomplish a (simple?) task. I extract strings from some logfiles, namely an ip-adress and bytes, by using regexes. I use a hash to store ip-adress and associated bytes. First i packed all logs in a temporary file

Re: getting one hash out of multiple files

2004-10-07 Thread Folker Naumann
John W. Krahn wrote: You may be able to do this by using a tied hash which will actually store the hash's contents in a file. perldoc DB_File perldoc AnyDBM_File perldoc perldbmfilter Tied hashes look fairly complicated to me, but i'll give them a try ;) #Print hash sorted by Host-IP-Adress

Re: getting one hash out of multiple files

2004-10-07 Thread John W. Krahn
Folker Naumann wrote: John W. Krahn wrote: This may work as it doesn't slurp the whole file(s) into memory: use warnings; use strict; use Socket; my %ipload; { local @ARGV = @sortlist; while ( ) { next unless / (\d+\.\d+\.\d+\.\d+) \w*\/\w* (\d+) [A-Z]+/ my $ip = inet_aton(

getting one hash out of multiple files

2004-10-06 Thread Folker Naumann
Hi there! I'm fairly new to Perl and need some help to acomplish a (simple?) task. I extract strings from some logfiles, namely an ip-adress and bytes, by using regexes. I use a hash to store ip-adress and associated bytes. First i packed all logs in a temporary file but it was getting too big.

Re: getting one hash out of multiple files

2004-10-06 Thread JupiterHost.Net
Folker Naumann wrote: Hi there! Hello, I'm fairly new to Perl and need some help to acomplish a (simple?) task. I extract strings from some logfiles, namely an ip-adress and bytes, by using regexes. I use a hash to store ip-adress and associated bytes. Sounds like you have the hard part done

RE: getting one hash out of multiple files

2004-10-06 Thread Charles K. Clarkson
Folker Naumann [EMAIL PROTECTED] wrote: : I'm fairly new to Perl and need some help to acomplish a : (simple?) task. : : I extract strings from some logfiles, namely an ip-adress : and bytes, by using regexes. I use a hash to store : ip-adress and associated bytes. First i packed all logs : in

Re: getting one hash out of multiple files

2004-10-06 Thread Folker Naumann
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

Re: getting one hash out of multiple files

2004-10-06 Thread JupiterHost.Net
Always always always: use strict; use warnings; (...) foreach $file (@sortlist){ my @sortlist = ... my %ipload =(); foreach my $file (@sortlist) { open(LOG,$file) or die Can't open $file: $!\n; @lines = LOG; my @lines = LOG; foreach my $logline (reverse(@lines)) { #Search for

Re: getting one hash out of multiple files

2004-10-06 Thread Folker Naumann
JupiterHost.Net wrote: Always always always: use strict; use warnings; Sorry, i just used (...) to indicate that i left out some lines of code. Including use strict, use warnings and all initialisations. foreach my $logline (reverse(@lines)) { #Search for Host-IP-Adress and bytes if(

Re: getting one hash out of multiple files

2004-10-06 Thread JupiterHost.Net
Always always always: use strict; use warnings; Sorry, i just used (...) to indicate that i left out some lines of code. Including use strict, use warnings and all initialisations. Then how did the code you posted work? Non of it was initialized with the scope it should have been. (IE any of

Re: getting one hash out of multiple files

2004-10-06 Thread JupiterHost.Net
Try this 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}