vasuperl has asked for the wisdom of the Perl Monks concerning the following question:

I have two perl files. in file1 if there is any error and executing continuously without exiting from the command prompt then how i have to implement timer. i am trying the below just for checking, but its not working.

$timeout=5; eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm $timeout; $nread = system('F:\perl1.pl'); alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors print "process terminated\n";} else { # didn't }

Replies are listed 'Best First'.
Re: How to use timeout in perl
by blindluke (Hermit) on Jan 08, 2015 at 13:35 UTC

      I already tried that one. But Time::Limit (limit.pm) module is not present in our perl version. We should not use external modules. Is there any other way to use timeout or alarm to exit from the script. Any help can be appreciated.

Re: How to use timeout in perl
by Anonymous Monk on Jan 08, 2015 at 14:12 UTC
    I think IPC::Run could help you here, it supports calling external commands with timeouts.