If nothing else you can keep adding subs for further benchmarking.use strict; use Benchmark qw/cmpthese/; my $count = 50000; my $regex2 = qr/^-([\d ]+)(.{40})(.{40})(.+)/; my $regex1 = qr/^-((\S+\s+){18})(.{40})(.{40})(.+)/; my @test_data; while ( <DATA> ) { push @test_data, $_; } cmpthese($count, { 'enlil' => sub { foreach my $line (@test_data) { if ($line =~ /^-3/) { $line =~ m/$regex2/; my $str_18_fields = $1; my $str_40_chars1 = $2; my $str_40_chars2 = $3; my $str_remain = $4; $str_40_chars1 =~ s!\|!_!; $str_40_chars2 =~ s!\|!_!; #print "\(ENLIL)str_18_fields = $str_18_fields\ +n"; #print "\(ENLIL)str_40_chars1 = $str_40_chars1\ +n"; #print "\(ENLIL)str_40_chars2 = $str_40_chars2\ +n"; #print "\(ENLIL)str_remain = $str_remain\n\ +n"; } } }, 'hackdaddy' => sub { foreach my $line (@test_data) { if ($line =~ /^-3/) { $line =~ m/$regex1/; my $str_18_fields = $1; my $str_40_chars1 = $3; my $str_40_chars2 = $4; my $str_remain = $5; $str_40_chars1 =~ s!\|!_!; $str_40_chars2 =~ s!\|!_!; #print "\(hackdaddy)str_18_fields = $str_18_field +s\n"; #print "\(hackdaddy)str_40_chars1 = $str_40_chars +1\n"; #print "\(hackdaddy)str_40_chars2 = $str_40_chars +2\n"; #print "\(hackdaddy)str_remain = $str_remain\ +n\n"; } } }, });
-enlil
In reply to Re: Efficient Log File Parsing with Regular Expressions
by Enlil
in thread Efficient Log File Parsing with Regular Expressions
by hackdaddy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |