Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Comparing pattern

by bv (Friar)
on Sep 21, 2009 at 15:22 UTC ( #796560=note: print w/replies, xml ) Need Help??


in reply to Re^2: Comparing pattern
in thread Comparing pattern

Did you read the documentation on study?

study attempts to make matches against a string more efficient, but incurs a one-time penalty for the time spent studying the string. It is most beneficial when you are doing many matches against a single string. You should benchmark to determine if you are getting any benefit from study. The first study in your code (line 10) is unnecessary, since you don't have a string in $_ to match against.

You keep saying "subroutine." Is this really in a sub? If so, are you reading in your patterns every time the sub is run? There's a major inefficiency. And once you solve that one, you can look at precompiling your expressions like I originally suggested.

print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))

Replies are listed 'Best First'.
Re^4: Comparing pattern
by mrc (Sexton) on Sep 21, 2009 at 17:54 UTC
    Yes, it is a subroutine. I need this script to scan all files for scams or other abuses. I'm using File::Find to search all files under a directory tree then call the subroutine for each file. Patterns are outside the sub.
    Based on your suggestion, I will precompile this way:
    ... my $list_regex = join '|', @patterns; my $regex_string = qr/$list_regex/is; ... if (/($regex_string)/) {print "\n$arg1\n$1\n";}
    As for study, I noticed a little slowness. Maybe it's not efficient in my case.

    I still have a big problem. Graff helped me with file slurp and scanner working few times faster than my original script, but I don't have experience with $/ or $_ and, if you check my last example, global $1 contains entire text between first pattern and second pattern:
    pattern1 some text pattern2 instead of this match: pattern1.*pattern2
    Can you please give me some advice? Thank you!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (9)
As of 2023-12-11 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?