HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Limit perl code execution time
Post new topic   Reply to topic    HTML Help Forum Index -> Perl
View previous topic :: View next topic  
Author Message
zylstra
Site Admin


Joined: 10 May 2004
Posts: 130

PostPosted: Tue Jun 27, 2006 5:02 pm     Limit perl code execution time Reply with quote

I need to limit the execution time of a particular line of code because it sometimes crashes the script:
Code:
      eval {$whois_info = `whois $domain`};
I would like the script to continue running even if the script stops that particular line of code.

How do I accomplish this?
zylstra
Site Admin


Joined: 10 May 2004
Posts: 130

PostPosted: Tue Jun 27, 2006 11:40 pm     Reply with quote

I found the answer with
Code:
$SIG{ALRM} = \&timed_out;
eval {
    alarm (10);
    $whois_info = `whois $domain`;
    alarm(0);           # Cancel the pending alarm if whois responds.
};
if ($@ =~ /GOT TIRED OF WAITING/) {
    print " Whois timed out:  $@ ";
}


sub timed_out {
    die "GOT TIRED OF WAITING";
}
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> Perl All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial