--- joost rust <[EMAIL PROTECTED]> wrote: > > hi all, > > Why is it that my CPU usage goes up to 100% when I use 5 or more ".*?" in my > regexp? Like this: > > (Checking one HTML file!!) > > if ($txt =~ > m/<form.*?name.*?=.*?>.*?<input.*?type="image"\ssrc="`imageP.*?>/is) > { > print "yeeha"; > } > > I don't need workarounds, just why? > > Juiced
I don't know why your CPU usage would go up to 100%, but I do know that your regex is broken and rather inneficient. If you want to see the internals of the regex engine, you can use the "re" pragma. Try the following snippet and see what pops out: ################################ use strict; use re 'debug'; my $txt =<<'END_HTML'; <html> <head> <title>Someform</title> </head> <body bgcolor="#FFFF"> <h1>This is a test of the emergency broadcast system</h1> <table> <tr> <td> <form name="someform" action="/cgi-bin/somescript.cgi"> <input type="hidden" name="test" value="test"> <input type="image" src="`imageP"> </form> </td> </tr> </table> </body> </html> END_HTML if ($txt =~ m/<form.*?name.*?=.*?>.*?<input.*?type="image"\s+src="`imageP.*?>/is) { print "yeeha"; } ################################ This will dump a lot of information, but once you trace through it, you can see *exactly* what your regular expression is doing. This is extremely useful if you can't figure out what a particular regex is matching (or not matching!). One thing: your /i modifier on the regex makes the regex case insensitive. This will add a lot of overhead to your regular expression as it's effectively trying to match twice as many letters. Also, you should add a plus (+) after the \s which is before "src". Otherwise, you're only able to match one space. You mentioned that you don't want workarounds so I won't provide one, but I do recommend that you read "Death to Dot Star!" (http://www.perlmonks.org/index.pl?node_id=24640). It details the problem inherent in using unspecific constructs like .* and .*?. Cheers, Curtis "Ovid" Poe ===== Senior Programmer Onsite! Technology (http://www.onsitetech.com/) "Ovid" on http://www.perlmonks.org/ __________________________________________________ Do You Yahoo!? Listen to your Yahoo! Mail messages from any phone. http://phone.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]