In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
Hi,
> I'm kind of new to Perl, so please forgive the question..
>
> I'm trying to use perl to read a file and then run a program using the
> file. I also want to use the alarm(x) function to skip to the next entry
> in the files if it times out. Here's what Ive go so far:
>
> open (TESTFILE, "< regression") || die "Can't open: regression_dgd\n";
> open (LOGFILE, "> regression.log") || die "Can't open: regression.log\n";
> print LOGFILE "\n\n\nStart of test run - $today1 $run\n";
> while ($line = <TESTFILE>)
> {
> alarm(62);
> print "Working...\n";
> $start=time;
> chomp($line);
> $cmd = "/node.ulm_bx";
> $full_line = join("",$line,$cmd);
> $jobrun = `$run $full_line`;
> print LOGFILE "$jobrun";
> $end = time;
> $totaltime = $end - $start;
> print LOGFILE "Time for test:$totaltime sec's\n\n\n";
> }
> close (TESTFILE);
> close (LOGFILE);
>
> It works fine, but when the alarm time gets exceeded, the script exits.
> What I would like it to do is just go to the next line in the TESTFILE.
Did you look at perldoc -f alarm? I just did and was able to come up
with this, which I think is similar to what you want:
while (my $line = <DATA>)
{
chomp($line);
print "Working on $line ...\n";
my $start = time;
eval
{
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
alarm 5;
while(1){}; # something that lasts way too long
};
if ($@)
{
die unless $@ eq "alarm\n"; # propagate unexpected
errors
# timed out
print "$line timed out\n";
next;
}
else
{
# didn't
}
my $end = time;
my $totaltime = $end - $start;
print "Time for test:$totaltime sec's\n\n\n";
}
__DATA__
aaa
bbb
ccc
--
Kevin Pfeiffer
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]