Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl: the Markov chain saw
 
PerlMonks  

Re: Slow Regex - How to Optimize

by rnahi (Curate)
on Aug 30, 2005 at 17:56 UTC ( [id://487962]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Slow Regex - How to Optimize

I would use a different approach, i.e. make a single string from your @sub_code and apply the search for each key just once.

#untested my $code = join("", @sub_code); foreach my $sub ( keys %SUBS ) { while ( $code =~ /\b$sub\b\(/g ) { push( @subs, $sub ) ; } }

Notice that your code has a subtle bug. If the same routine is used twice in oone line, you'll get it only once. E.g.:  sqrt(x) + sqrt(y)

BTW, what is that $key in your code?

Replies are listed 'Best First'.
Re^2: Slow Regex - How to Optimize
by Anonymous Monk on Aug 30, 2005 at 19:16 UTC
    Notice that your code has a subtle bug.
    Even if he is running the code through CPP first (to strip out comments, expand macros, rejoin lines), he still has plenty of corner cases to worry about (strings, fucntion pointers, etc)...
    #define p printf int mai\ n/*this is a comment: main()*/(int argc, char **argv) { int (*f)(int, char **) = &main; p("hello world: main()\n"); if(argc>0) f((argc-1),argv); }
      Oh, and don't forget that [^a-zA-Z] matches "(" and that C identifiers can have digits and underscores...
      _foo2bar((4),2);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://487962]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.