Skip to content

Instantly share code, notes, and snippets.

@tagomoris
Created February 8, 2011 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tagomoris/816054 to your computer and use it in GitHub Desktop.
Save tagomoris/816054 to your computer and use it in GitHub Desktop.
dankogaiスクリプト tsv の処理対象を $tsv に変えただけ
#!/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