in reply to Re: A pretty simple perl script..
in thread A pretty simple perl script..

"doesn't work properly" = it showes some names last connected two weeks or something like that but i know for sure that those names last connected yesterday and even today.

anyway, i forgot to mention something. let's say that name1 decides to join the server using nickname "PERL - name1". He is still recognised by the server as an admin and i would like the script to do the same
Here is some data:

L 03/31/2006 - 00:18:19: "smilE :) x3Oni<109><STEAM_ID_LAN><>" connect +ed, address "82.78.68.195:27005" L 03/31/2006 - 00:19:40: "smilE :) Ramon<110><VALVE_ID_LAN><>" connect +ed, address "86.55.92.11:27005" L 03/31/2006 - 00:23:06: "smilE :) Ramon<111><VALVE_ID_LAN><>" connect +ed, address "86.55.92.11:27005" L 03/31/2006 - 00:33:50: "smilE :) Ramon<112><VALVE_ID_LAN><>" connect +ed, address "86.55.92.11:27005" L 03/31/2006 - 00:35:09: "mT - Loly<113><STEAM_ID_LAN><>" connected, a +ddress "81.24.24.209:27005" L 03/31/2006 - 00:35:31: "mT - Mini^Me<114><STEAM_ID_LAN><>" connected +, address "81.196.153.50:27005" L 03/31/2006 - 00:36:42: "mT - Grasutza<115><STEAM_ID_LAN><>" connecte +d, address "81.24.24.207:27005" L 03/31/2006 - 00:38:05: "rrr<116><VALVE_ID_LAN><>" connected, address + "82.208.167.71:27005" L 03/31/2006 - 00:38:35: "rrr<117><VALVE_ID_LAN><>" connected, address + "82.208.167.71:27005" L 03/31/2006 - 00:41:03: "mT - kdt<118><STEAM_ID_LAN><>" connected, ad +dress "82.76.231.13:27005" L 03/31/2006 - 01:18:03: "smilE :) x3Oni<119><STEAM_ID_LAN><>" connect +ed, address "82.78.68.195:27005" L 03/31/2006 - 01:28:18: "astralis[mix] . bullet[A]<120><VALVE_ID_LAN> +<>" connected, address "86.106.193.40:27005" L 03/31/2006 - 01:28:43: "astralis[mix] . BNj-_-<121><STEAM_ID_LAN><>" + connected, address "81.24.24.227:27005" L 03/31/2006 - 01:30:10: "astralis[mix] . sUIFTI-_^<122><VALVE_ID_LAN> +<>" connected, address "84.247.25.70:27005" L 03/31/2006 - 01:31:30: "astralis[mix] . AD0n<123><STEAM_ID_LAN><>" c +onnected, address "85.120.80.131:27005"


and users.ini:
x30ni:password:131071 Ramon:password:131071 Loly:password:131071 Mini:password:131071 Grasutza:password:131071 bullet:password:131071 Ad0n:password:131071

Replies are listed 'Best First'.
Re^3: A pretty simple perl script..
by GrandFather (Saint) on Apr 01, 2006 at 01:00 UTC

    Sample code using the data you provided. Note that the required parameters are being extracted using a regex rather than split and that the name search code now uses index rather than a regex.

    use strict; use warnings; my $search='\bconnected, address\b' ; my @users = qw(x3Oni Ramon Loly Mini Grasutza bullet Ad0n); my %R; print "search: @users\n"; while (<DATA>) { next unless /$search/o; s/L /:/; s/<.*>//; s/$search//o; s/ - /-/; my ($time, $name, $addy) = m!([-\d/:]*)\s*"([^"]*)"[^"]*"([^"]*)!; my $cleanName = name_match ($name); next unless $cleanName; my $nTime = fix_time ($time); my $rec = "$nTime $time $name"; if (! exists $R{$cleanName}) { $R{$cleanName} = $rec; next; } my ($t) = $R{$cleanName} =~ /^(\d+)/; $R{$cleanName} = $rec if $nTime > $t; } print "--------------------------\n"; my @values = sort values %R; foreach my $v (@values) { print STDOUT (split /:/, $v, 2)[1]; print "\n"; } # compare names, log names may have attributes; like sub name_match { my $test = shift; $test =~ tr/"//d; for (@users) { my $pos = length ($test) - length; my $at = index ($test, $_); return $_ if $pos == $at; } return ""; } # convert time from 'L: MM/DD/YYYY - hh:mm:ss' to YYYYMMDDhhmmss # which makes time comparison a doddle sub fix_time { local $_ = shift; s/.//; tr/://d; my($date, $time) = split /-/; my ($m, $d, $y) = split "/", $date; return "$y$m$d$time"; } __DATA__ L 03/31/2006 - 00:18:19: "smilE :) x3Oni<109><STEAM_ID_LAN><>" connect +ed, address "82.78.68.195:27005" L 03/31/2006 - 00:19:40: "smilE :) Ramon<110><VALVE_ID_LAN><>" connect +ed, address "86.55.92.11:27005" L 03/31/2006 - 00:23:06: "smilE :) Ramon<111><VALVE_ID_LAN><>" connect +ed, address "86.55.92.11:27005" L 03/31/2006 - 00:33:50: "smilE :) Ramon<112><VALVE_ID_LAN><>" connect +ed, address "86.55.92.11:27005" L 03/31/2006 - 00:35:09: "mT - Loly<113><STEAM_ID_LAN><>" connected, a +ddress "81.24.24.209:27005" L 03/31/2006 - 00:35:31: "mT - Mini^Me<114><STEAM_ID_LAN><>" connected +, address "81.196.153.50:27005" L 03/31/2006 - 00:36:42: "mT - Grasutza<115><STEAM_ID_LAN><>" connecte +d, address "81.24.24.207:27005" L 03/31/2006 - 00:38:05: "rrr<116><VALVE_ID_LAN><>" connected, address + "82.208.167.71:27005" L 03/31/2006 - 00:38:35: "rrr<117><VALVE_ID_LAN><>" connected, address + "82.208.167.71:27005" L 03/31/2006 - 00:41:03: "mT - kdt<118><STEAM_ID_LAN><>" connected, ad +dress "82.76.231.13:27005" L 03/31/2006 - 01:18:03: "smilE :) x3Oni<119><STEAM_ID_LAN><>" connect +ed, address "82.78.68.195:27005" L 03/31/2006 - 01:28:18: "astralis[mix] . bullet[A]<120><VALVE_ID_LAN> +<>" connected, address "86.106.193.40:27005" L 03/31/2006 - 01:28:43: "astralis[mix] . BNj-_-<121><STEAM_ID_LAN><>" + connected, address "81.24.24.227:27005" L 03/31/2006 - 01:30:10: "astralis[mix] . sUIFTI-_^<122><VALVE_ID_LAN> +<>" connected, address "84.247.25.70:27005" L 03/31/2006 - 01:31:30: "astralis[mix] . AD0n<123><STEAM_ID_LAN><>" c +onnected, address "85.120.80.131:27005"

    Prints:

    search: x3Oni Ramon Loly Mini Grasutza bullet Ad0n -------------------------- 03/31/2006-00:33:50: smilE :) Ramon 03/31/2006-00:36:42: mT - Grasutza 03/31/2006-00:38:35: rrr 03/31/2006-01:18:03: smilE :) x3Oni

    I'm sure you understand now that you can replace the <DATA> with <FileHandleOfYourChoice> and that the contents of the users array can be filled from an external file too.


    DWIM is Perl's answer to Gödel