Thread Regülarer Ausdrück zu einem hash array
(19 answers)
Opened by Tom99 at 2008-10-04 15:42
Hast du dir meinen Beitrag durchgelesen?
Naja, durch ein paar kleine Modifikationen an meinem geposteten Skript, läuft es: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $file = 'test.txt'; my %proc = ( 'ClientConnect' => sub{ print "Client $_[0] connected\n" }, 'ClientBegin' => sub{ print "Client $_[0] began\n" }, 'ClientUserinfo' => sub{ my $line = shift; if ( $line =~ /(\d+) \\(.*)/ ) { print "Client $1: $2\n"; my $logline = $2; my %player_info = split /\\/, $logline; print Dumper \%player_info; } # if }, ); open( my $fh, '<', $file ) or die "Cannot open file '$file': $!"; while ( my $line = <$fh> ) { chomp($line); if ( $line =~ /^\s+(\d{1,2}:\d{2}) ((\w+):(?: )?(.*)?)/ ) { if ( defined $3 and defined $4 ) { $proc{$3}->($4) if exists $proc{$3}; } # if } # if } # while __END__ Ich habe $logline einfach anhand von \ gesplittet. Weiter unten habe ich noch die Prüfung hinzugefügt, ob es eine Routine für die jeweilige Aktion gibt. (bsw.: ClientConnect) MfG perl -E'*==*",s;;%ENV=~m,..$,,$&+42;e,$==f;$"++for+ab..an;@"=qw,u t,,print+chr;sub f{split}say"@{=} me"'
|