redhotpenguin has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks,
I'm a bit of a klutz with regular expressions, but I've taken a shot at making this script which parses log entries for a Pure Ftpd server I run. I'm looking for ways to improve it's efficiency and readability. The log entries are separated by carraige returns and the elements by single spaces.
#!/usr/bin/perl use strict; use warnings; my $data = 'Jul 30 19:39:06 server pure-ftpd: (user@68.158.32.189) [NOTICE] /home/shows//Genesis/Genesis 1978-06-24 FLAC/genesis1978-06-24-prefm-d1t04.flac downloaded (71074015 bytes, 60.83KB/sec) Jul 30 19:39:23 server pure-ftpd: (user@68.17.66.125) [NOTICE] /home/shows//Simon and Garfunkel/Simon and Garfunkel 2003-10-16/SG2003-10-16-d2t03.shn downloaded (2075533 bytes, 115.25KB/sec)'; my @lines = split "\n", $data; foreach my $line (@lines) { $line =~ m/^(\w+)\s(\d+)\s(\S+)\s\w+\s\D+\s\D(\w+) \x40(\d+\W\d+\W\d+\W\d+)\D\s\S+\s(.*) \s+\w+\s+\S?(\d+)\s\w+\S\s(\d+\W\d+)/; print "Month is: $1\n"; print "Day is: $2\n"; print "Time is: $3\n"; print "User is: $4\n"; print "IP is: $5\n"; print "File is: $6\n"; print "Size is : $7\n"; print "Speed is : $8\n"; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pure Ftpd log regex
by Zaxo (Archbishop) on Jul 31, 2004 at 06:08 UTC | |
|
Re: Pure Ftpd log regex
by BrowserUk (Patriarch) on Jul 31, 2004 at 07:29 UTC | |
|
Re: Pure Ftpd log regex
by Dietz (Curate) on Jul 31, 2004 at 09:58 UTC | |
|
Re: Pure Ftpd log regex
by jfroebe (Parson) on Jul 31, 2004 at 06:58 UTC | |
by davido (Cardinal) on Jul 31, 2004 at 07:11 UTC | |
by jfroebe (Parson) on Jul 31, 2004 at 07:13 UTC | |
|
Re: Pure Ftpd log regex
by Aristotle (Chancellor) on Jul 31, 2004 at 20:01 UTC |