Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: How to identify invalid reg. expr.?

by mephit (Scribe)
on Jun 06, 2002 at 19:44 UTC ( [id://172331]=note: print w/replies, xml ) Need Help??


in reply to Re: How to identify invalid reg. expr.?
in thread How to identify invalid reg. expr.?

Hmm, I'd never heard of alarm before now, so I just threw a little something together to test:
#!/usr/bin/perl -w BEGIN { #stuff } alarm 10; #the bulk of the program snipped. $_ = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; print "Match\n<p>" if /a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*[b]/;
That example is given in the camel book as one that won't finish until after the heat death of the universe. Without the alarm, it does indeed hog the CPU, but with the alarm in there, the script just dies after 10 seconds, which should be plenty long enough for any "valid" request to run. That can be changed, of course. I guess I'd also need to put in a signal handler to do any cleanup when the alarm goes off. Hmm, and I suppose I should also try putting the alarm in the "search_by_regex routine", (since that's the only area I'm concerned about), but possibly look for a way to not "die" if the delay is from a slow database or something other than a wonky regex.

I also implemented merlyn's eval/regex solution from this node in this thread (or just scroll down, maybe).

So, is this a viable solution, or are there still problems with it? Thanks.

--

There are 10 kinds of people -- those that understand binary, and those that don't.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-18 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found