"be consistent" | |
PerlMonks |
Re: can any reply out with a better code than this??by ysth (Canon) |
on Dec 06, 2007 at 07:27 UTC ( [id://655295]=note: print w/replies, xml ) | Need Help?? |
Better in what sense? If the string may contain characters special to a regex that you want treated as regular characters to match, do /(\Q$string\E){3}/. Make the match non-capturing, since you are unlikely to be using the captured result: /(?:\Q$string\E){3}/. If the "3" is always the same and for some reason it isn't fast enough, try repeating it: /\Q$string$string$string\E/. Save the regex in a variable and reuse it: my $regex = qr/\Q$string$string$string\E/; ... if ($line =~ $regex) ....
In Section
Seekers of Perl Wisdom
|
|