Beefy Boxes and Bandwidth Generously Provided by pair Networks
"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 ( #655295=note: print w/replies, xml ) Need Help??


in reply to can any reply out with a better code than this??

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) ....

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://655295]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2021-03-03 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (81 votes). Check out past polls.

    Notices?