Nikola Janceski wrote at Fri, 07 Jun 2002 15:02:22 +0200: > perhaps use qr// to "precompile" the search instead and use that new precompiled var >within your > loop so you don't evaluate the if conditions each looptime. > > my $search; > if ( $WholeMatchOnly ) > { > if ( $IgnoreCase ) > { $search = qr/^\($pattern\)$/i } > else > { $search = qr/^\($pattern\)$/ } > } > else > { > if ( $IgnoreCase ) > { $search = qr/\($pattern\)/i } > else > { $search = qr/\($pattern\)/ } > } > }
Even in the above there's much redundancies and it's hard to maintain. I think we should exploit the power of Perl: for ($pattern) { $_ = "\($_\)"; # Capturing $_ = "(?i)$_" if $IgnoreCase; $_ = '^' . $_ . '$' if $WholeMatchOnly; } print "matches" if $text =~ /$pattern/; Now it's exactly expressed what the algorithm has to do: Take a pattern { Capture the content IgnoreCase if neccessary WholeMatchOnly if necessary } Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]