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/


Reply via email to