If the log format is reliably consistent with the example you gave, a simple line-by-line reading should be plenty easy, quick and maintainable; and it looks like the kind of situation where a hash data structure would be handy:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @fieldnames = ( 'Team', 'Score', 'Player', 'Kills', 'Deaths', 'Team Kills', 'Suicides', 'Objective', 'Results for +Map' ); my $matchfield = join '|', @fieldnames; my %entry; my ( $map, $team, $player, $datafor ); while (<DATA>) { s/[\r\n]+//; # OS-neutral alternative to "chomp" my ( $timestamp, $data ) = unpack( "A26 A*", $_ ); next unless ( length( $data ) and $data =~ /$matchfield/ ); $timestamp =~ tr/[]//d; my ( $fieldname, $fieldval ) = split( /: /, $data, 2 ); $fieldname =~ s/^[\s*]+//; if ( $fieldname eq 'Results for Map' ) { processEntry( \%entry ); %entry = (); $entry{map} = $fieldval; $entry{time} = $timestamp; } elsif ( $fieldname eq 'Team' ) { $datafor = $fieldname; $team = $fieldval; $entry{$team} = {}; } elsif ( $fieldname eq 'Player' ) { $datafor = $fieldname; my $uid; ( $player, $uid ) = ( $fieldval =~ /(\w+) .uid: (\w+)/ ); $entry{$team}{$player}{uid} = $uid; } elsif ( $fieldname eq 'Score' ) { if ( $datafor eq 'Team' ) { $entry{$team}{Score} = $fieldval; } else { $entry{$team}{$player}{Score} = $fieldval; } } else { $entry{$team}{$player}{$fieldname} = $fieldval; } } processEntry( \%entry ); sub processEntry { my $href = shift; return unless ( scalar keys %$href ); print Dumper $href; } __DATA__ [Thu Sep 21 17:48:38 2006] [Thu Sep 21 17:48:38 2006] ------------------------------------------ [Thu Sep 21 17:48:38 2006] Server started. [Thu Sep 21 18:37:22 2006] Client connected: Alpha [Thu Sep 21 18:37:31 2006] Client connected: Bravo [Thu Sep 21 18:38:20 2006] Client connected: Charlie [Thu Sep 21 18:39:18 2006] Client connected: Delta [Thu Sep 21 18:53:36 2006] [Thu Sep 21 18:53:36 2006] *** Results for Map: Worlds\ReleaseMultipla +yer\Bypass [Thu Sep 21 18:53:36 2006] [Thu Sep 21 18:53:36 2006] Team: Team 1 [Thu Sep 21 18:53:36 2006] Score: 93 [Thu Sep 21 18:53:36 2006] [Thu Sep 21 18:53:36 2006] Player: Alpha (uid: ad7023b7f46271acd31e1bd +287613b6d) [Thu Sep 21 18:53:36 2006] Score: 55 [Thu Sep 21 18:53:36 2006] Kills: 14 [Thu Sep 21 18:53:36 2006] Deaths: 15 [Thu Sep 21 18:53:36 2006] Team Kills: 0 [Thu Sep 21 18:53:36 2006] Suicides: 0 [Thu Sep 21 18:53:36 2006] Objective: 0 [Thu Sep 21 18:53:36 2006] [Thu Sep 21 18:53:36 2006] Player: Bravo (uid: 5fdcc95043dc4dac9d7b4af +b8469eb4f) [Thu Sep 21 18:53:36 2006] Score: 38 [Thu Sep 21 18:53:36 2006] Kills: 11 [Thu Sep 21 18:53:36 2006] Deaths: 17 [Thu Sep 21 18:53:36 2006] Team Kills: 0 [Thu Sep 21 18:53:36 2006] Suicides: 0 [Thu Sep 21 18:53:36 2006] Objective: 0
In reply to Re: regex issues with /gc in log analysis...
by graff
in thread regex issues with /gc in log analysis...
by EvanK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |