In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > On Sat, 12 Jul 2003, Kevin Pfeiffer wrote: > >> 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: [...]
>> 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 > > Keven.. This looks really good.. _i_ > Is it the "eval" that keeps the alarm from kicking the script out of the > loop? Someone else can more precisely explain this, but when the alarm "goes off" it calls a subroutine that causes your program to seemingly die with the message "alarm" - but this is trapped inside the magical, "every cat deserves another life" eval block, which then passes the die message out to where your still running program then does something sensible (like going on to the next iteration). -K -- Kevin Pfeiffer International University Bremen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]