in reply to Re: Looking for ideas on how to optimize this specialized grep
in thread Looking for ideas on how to optimize this specialized grep
'let the "." match any character whatsoever, while still allowing "^" and "$" to match, respectively, just after and just before newlines within the string'
I didn't think of example that needs this. Do you have any example case like 'little princess' example for /ms?The result for my 319Mb test mail box was like this.use strict; use warnings; use File::Find; use Data::Dumper; my %addresses; sub test1 { my ($from); find(sub { return unless -f $_; open my $fh, '<', $_ or die; local $/ = ''; # "Paragraph" mode, reads a block of t +ext to next \n\n $_ = <$fh>; # Read Header block ($from)= $_ =~ /^From:(.*)/m; # /m to anchor #print "$from\n"; close $fh; }, glob('./009_mailtest/*')); #print Dumper \%addresses; } sub test2{ binmode(STDOUT,":utf8"); my ($from,$bgn,$end,$len); find(sub { return unless -f $_; open my $fh, '<:utf8', $_ or die; local $/ = ''; # "Paragraph" mode, reads a block of t +ext to next \n\n $_ = <$fh>; # Read Header block $bgn=index($_,"From:",0) + length("From:"); $end=index($_,chr(10),$bgn+1); $len=$end - $bgn; $from=substr($_, $bgn, $len); #print "$from\n"; close $fh; }, glob('./009_mailtest/*')); } my($start,$end); $start=(times)[0]; &test1; $end=(times)[0]; print "with regex=" . ($end - $start) . "sec\n"; $start=(times)[0]; &test2; $end=(times)[0]; print "without regex=" . ($end - $start) . "sec\n";
with regex=0.296875sec without regex=0.34375sec
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Looking for ideas on how to optimize this specialized grep
by furry_marmot (Pilgrim) on Jan 25, 2011 at 21:16 UTC | |
by remiah (Hermit) on Jan 26, 2011 at 08:00 UTC | |
by furry_marmot (Pilgrim) on Jan 26, 2011 at 18:30 UTC | |
by remiah (Hermit) on Jan 27, 2011 at 06:04 UTC | |
by furry_marmot (Pilgrim) on Jan 28, 2011 at 00:55 UTC | |
|