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

Re: Losing control of large regular expressions

by sleepingsquirrel (Chaplain)
on Jan 12, 2005 at 00:49 UTC ( [id://421470]=note: print w/replies, xml ) Need Help??


in reply to Losing control of large regular expressions

You can run the regex in another process...
#!/usr/bin/perl eval { local $SIG{ALRM} = sub { die('ALARM'); }; alarm(5); #use forking open to start another processes unless ($pid = open REGEX, "-|") { print "starting long regex match...\n"; #This string will take close to forever to match $_ = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +aaaa"; print "matched\n" if /a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a +*a*[b]/; exit; } while (<REGEX>) #read results from long running process { print "$_"; } alarm(0); }; if ($@ =~ /ALARM/) { print "got alarm\n"; kill 9, $pid; } else { print "no alarm\n" }


-- All code is 100% tested and functional unless otherwise noted.

Log In?
Username:
Password:

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

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

    No recent polls found