#!/usr/bin/perl -w
use strict;
my $line = '76.172.202.159 - - [31/Aug/2007:15:58:15 -0600] "GET / HTT
+P/1.1" 200 29692 "http://www.paperbackswap.com/forum/view_topic.php?t
+=70235&ls=" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8
+.0.12) Gecko/20070508 Firefox/1.5.0.12"';
my ($host,$date,$url_with_method,$status,$size,$referrer,$agent) = $li
+ne =~
m/^(\S+) - - \[(\S+ [-+]\d{4})\] "(\S+ \S+ [^"]+)" (\d{3}) (\d+|-)
+ "(.*?)" "([^"]+)"$/
or warn "match failed!";
print "$host\n$date\n$url_with_method\n$status\n$size\n$referrer\n$age
+nt\n";
or:
#!/usr/bin/perl -w
use strict;
my $line = '76.172.202.159 - - [31/Aug/2007:15:58:15 -0600] "GET / HTT
+P/1.1" 200 29692 "http://www.paperbackswap.com/forum/view_topic.php?t
+=70235&ls=" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8
+.0.12) Gecko/20070508 Firefox/1.5.0.12"';
if ( my ($host,$date,$url_with_method,$status,$size,$referrer,$agent)
+= $line =~
m/^(\S+) - - \[(\S+ [-+]\d{4})\] "(\S+ \S+ [^"]+)" (\d{3}) (\d+|-)
+ "(.*?)" "([^"]+)"$/
) {
print "$host\n$date\n$url_with_method\n$status\n$size\n$referrer\n
+$agent\n";
}
else {
warn "match failed!";
}
You might take a look at the Regexp::Log module. |