Created
February 8, 2011 07:49
-
-
Save tagomoris/816054 to your computer and use it in GitHub Desktop.
dankogaiスクリプト tsv の処理対象を $tsv に変えただけ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
# original: http://blog.livedoor.jp/dankogai/archives/50924886.html | |
use strict; | |
use warnings; | |
use Benchmark qw/timethese cmpthese/; | |
my $logline = | |
q{localhost.local - - [04/Oct/2007:12:34:56 +0900] "GET /apache_pb.gif HTTP/1.1" 200 2326 "http://www.dan.co.jp/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7"}; | |
my (@logline) = | |
( $logline =~ | |
m!^(.*) (.*) (.*) \[(.*)\] "(.*)" (.*) (.*) "(.*)" "(.*)"! ); | |
my $tsv = join "\t", @logline; | |
cmpthese( | |
timethese( | |
0, | |
{ | |
rx_naive => sub { | |
my (@l) = | |
( $logline =~ | |
m!^(.*) (.*) (.*) \[(.*)\] "(.*)" (.*) (.*) "(.*)" "(.*)"! | |
); | |
}, | |
rx_optim => sub { | |
my (@l) = | |
( $logline =~ | |
m!^([^\s]*) [^\s]* [^\s]* \[([^]]*)\] "([^"]*)" ([^\s]*) [^\s]* "([^"]*)" "([^"]*)"! | |
); | |
}, | |
tsv => sub { my (@l) = split /\t/, $tsv }, | |
} | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment