Ekimino has asked for the wisdom of the Perl Monks concerning the following question:
This is the code that matches wrongly.Logfile Example "ct1<4><BOT><>" entered the game "ct1<4><BOT><>" joined team "CT" "terror1<1><BOT><TERRORIST>" attacked "ct1<4><BOT><CT>" with "p228" (d +amage "26") (damage_armor "0") (health "74") (armor "0") "terror1<1><BOT><TERRORIST>" attacked "ct1<4><BOT><CT>" with "p228" (d +amage "27") (damage_armor "0") (health "47") (armor "0") "terror1<1><BOT><TERRORIST>" attacked "ct1<4><BOT><CT>" with "p228" (d +amage "27") (damage_armor "0") (health "20") (armor "0") "terror1<1><BOT><TERRORIST>" attacked "ct1<4><BOT><CT>" with "p228" (d +amage "28") (damage_armor "0") (health "-8") (armor "0") "terror1<1><BOT><TERRORIST>" killed "ct1<4><BOT><CT>" with "p228" "ct1<4><BOT><CT>" attacked "terror2<2><BOT><TERRORIST>" with "fiveseve +n" (damage "12") (damage_armor "2") (health "88") (armor "98") "ct1<4><BOT><CT>" attacked "terror3<3><BOT><TERRORIST>" with "fiveseve +n" (damage "13") (damage_armor "0") (health "2") (armor "0")
As you may see in the logfile example player named "ct1" didn't killed anyone, but It's name appears 4 times as line starter, which my regular expressions treats as 4 kills. Is the error in starting my regexp with (.*)?. If it's not too much to ask I would also like to know what do think of this part, is it correct to just copy the hash?# kill / killed logging # $1 = killer # $2 = killed # $3 = weapon used if($_ =~ m/^"(.+)<.+><.+><.+>" killed "(.+)<.+><.+><.+>" with "(.+ +)"/){ $players{$1}{"frags"} += 1; $players{$2}{"deaths"} += 1; }
Thank you for taking the time to read and think about it.# The skeleton of each player hash my %skeleton_player = ( "team_side" => "0", "frags" => "0", "deaths" => "0", "suicides" => "0", "dmg_done" => "0", "dmg_received" => "0", "team_damage" => "0", "team_kills" => "0", ); my %players = (); my @file = <>; foreach(@file){ # Deletes the time information from each log line $_ =~ s/L [0-9]+\/[0-9]+\/[0-9]{4} - [0-9]+\:[0-9]+\:[0-9]+\: //g; # Creates a hash of a hash for players # # And Copies %skeleton_player to it # # %players # - %player 1 # -frags # -deaths # -etc.. # - %player 2 # -etc.. if($_ =~ m/"(.*)<.*><.*><.*>" entered the game/){ unless(exists $players{$1}){ $players{$1} = %skeleton_player; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question regarding exact regexp matching
by jethro (Monsignor) on Jun 28, 2012 at 22:15 UTC | |
by Ekimino (Novice) on Jun 28, 2012 at 22:29 UTC | |
|
Re: Question regarding exact regexp matching
by aaron_baugher (Curate) on Jun 28, 2012 at 22:23 UTC | |
|
Re: Question regarding exact regexp matching
by CountZero (Bishop) on Jun 28, 2012 at 22:22 UTC |