Is $table a compiled regexp? If it's not, you're compiling regexps over and over again for nothing. In fact, there's no reason to have multiple regexps.
use Regexp::List qw( ); my $re = Regexp::List->new(modifiers => 'i') ->list2re( map lc($hash{$_}[0]), keys %hash ); # or: # my ($re) = map qr/$_/i, # join '|', # map quotemeta(lc($hash{$_}[0])), # keys %hash; while (my $cur_line = <$fh_log>) { while ($cur_line =~ /($re)/g) { my $table = lc($1); if ($tables{$table}) { # Count up how many times this table is referenced. $table_stats{$table}++; $table_refs++; } } }
An alternative solution would be to extract the words in $cur_line and look for them in a hash.
my %tables = map { lc($hash{$_}[0]) => 1 } keys %hash; while (my $cur_line = <$fh_log>) { while ($cur_line =~ /(\w+)/g) { my $table = lc($1); if ($tables{$table}) { # Count up how many times this table is referenced. $table_stats{$table}++; $table_refs++; } } }
I suspect the first method is better.
In reply to Re: Perl Optimization
by ikegami
in thread Perl Optimization
by Chivalri
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |