good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: 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 reply to Re: can any reply out with a better code than this??
by ysth
|
|