in reply to Simple log parser I hope!

picabotwo,
The difficulty in your question is that your limited data sample requires us to assume a lot. The following works with the data provided.
#!/usr/bin/perl use constant MAX_OPEN_CALLS => 100; use strict; use warnings; my $log = $ARGV[0] or die "Usage: $0 <log_file>"; open(my $fh, '<', $log) or die "Unable to open '$log' for reading: $!" +; my %call; { local $/ = '=============================================='; while (<$fh>) { my ($type, $id, $info) = parse_rec($_); if ($type eq 'INIT') { next if $info !~ /TCH/; die "Multiple calls with id '$id' without response" if exi +sts $call{$id}; $call{$id} = undef; } elsif ($type eq 'RESPONSE') { next if ! exists $call{$id}; print "Call with id '$id' has a Px,Py of '$info'\n"; delete $call{$id}; } die "Too many unanswered calls" if keys %call > MAX_OPEN_CALLS +; } } sub parse_rec { my ($rec) = @_; my ($type) = $rec =~ /CALL_(\w+)/; $type = '' if ! defined $type; my ($id) = $rec =~ /TRAN_ID\s+(\S+)/; my $info; if ($type eq 'INIT') { ($info) = $rec =~ /CHAN_TYPE\s+(\S+)/; } elsif ($type eq 'RESPONSE') { ($info) = $rec =~ /Px,Py\s*=\s*(\S+)/; } $info = '' if ! defined $info; return ($type, $id, $info); }

Cheers - L~R

Replies are listed 'Best First'.
Re^2: Simple log parser I hope!
by picabotwo (Initiate) on Sep 18, 2008 at 16:10 UTC
    Hash table was exactly what I was looking for. Thanks again! Josh
Re^2: Simple log parser I hope!
by picabotwo (Initiate) on Sep 18, 2008 at 19:12 UTC
    Thanks that code worked exactly as I needed it. I just did a few small small tweaks to get it do to what I needed!
    #!/usr/bin/perl use constant MAX_OPEN_CALLS => 100; use strict; use warnings; #my $log = $ARGV[0] or die "Usage: $0 <log_file>"; #open(my $fh, '<', $log) or die "Unable to open '$log' for reading: $! +"; my %call; { local $/ = '=============================================='; while (<>) { my ($type, $id, $info) = parse_rec($_); print "$_\n\n"; if ($type eq 'INIT') { next if $info !~ /TCH/; $call{$id} = 1; } elsif ($type eq 'RESPONSE') { next if ! exists $call{$id}; print "Call with id '$id' has a Px,Py of '$info'\n"; print "===============================================\n"; (my @args) = $info =~ /(.{8})(.{8}),(.{8})(.{8})/; #print "@args\n"; my $cprogram = `./decrypt @args`; print $cprogram; print "===============================================\n"; delete $call{$id}; } die "Too many unanswered calls" if keys %call > MAX_OPEN_CALLS +; } } sub parse_rec { my ($rec) = @_; my ($type) = $rec =~ /CALL_(\w+)/; $type = '' if ! defined $type; my ($id) = $rec =~ /TRAN_ID\s+(\S+)/; my $info; if ($type eq 'INIT') { ($info) = $rec =~ /CHAN_TYPE\s+(\S+)/; } elsif ($type eq 'RESPONSE') { ($info) = $rec =~ /Px,Py\s*=\s*(\S+)/; } $info = '' if ! defined $info; return ($type, $id, $info); }