Thanks for the reply, but sometimes I don't know where is the code that cause 
the infinite loop. Is there such as thing as perl configuration file, to set 
the execution time for any code, any where in the program just like php.ini 
file. Thanks.

----- Original Message ----
From: Chas. Owens <[EMAIL PROTECTED]>
To: Keenlearner <[EMAIL PROTECTED]>
Cc: beginners@perl.org
Sent: Friday, April 11, 2008 16:05:07
Subject: Re: Perl maximum execution time

On Thu, Apr 10, 2008 at 9:25 PM, Keenlearner <[EMAIL PROTECTED]> wrote:
> Hello, I have had been programming in PHP for a while, new to perl. I
>  got a perl code bug where it will go to infinite loop. So is there a
>  maximum execution time that I could set in perl just like in PHP ?
>  Thanks
snip

You can set an signal to go off after X seconds with the alarm* function:

#!/usr/bin/perl

use strict;
use warnings;

my $timeout = 5*60; #timeout after five minutes

eval {
    local $SIG{ALRM} = sub { die "timeout\n" };
    alarm $timeout;
        #stuff you want to run in under five minutes
};
die unless $@ eq "timeout\n" if $@;

* http://perldoc.perl.org/functions/alarm.html

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/






Send instant messages to your online friends http://uk.messenger.yahoo.com




Send instant messages to your online friends http://uk.messenger.yahoo.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to