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
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
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(
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.
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
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
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
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
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(
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
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}
11 matches
Mail list logo