Jay Savage <[EMAIL PROTECTED]> wrote: On 1/11/07, hOURS wrote: [snip] > Some modifications I made: I changed the names of the programs being tested > to fit what I had. I reduced the alarm time from one hour down to a few > seconds. I included statements to print out error messages. (The original if > and else blocks just had comments.) And lastly, for my test, since I'll be > checking a large number of programs for infinite loops, I encased this code > in a for loop. As you can see below, it executes the code 4 times, testing > the programs, infinite1.pl, infinite2.pl, infinite3.pl, and infinite4.pl. > Those are all very simple programs. 1, 2, and 4 are identical: > $x = 3 + 4; > print $x; > Running them gives the expected 7 on the screen. For infinite3.pl I > encased that in an endless loop: > while (1) { > $x = 3 + 4; > print $x; > } > Running this gives the expected never-ending stream of 7's. > Here's the finished code for error checking: > for($number = 1; $number < 5; $number +=1) { > $ProgramName = "infinite" . $number . ".pl"; > eval { > local $SIG{ALRM} = sub { die "$ProgramName timed out\n" }; > alarm 9; > require $ProgramName; > alarm 0; > }; > if($@) { > if($@ =~ /timed out/) { > print "timeout\n"; # timeout > } else {print "some other error\n"; # some other error > } > } > } > > So when I run this code and check those four little programs for > errors I get the following: > some other error > some other error > some other error > some other error > > > I don't know why I get 4 errors and not one, and why they're of the > wrong type. Any help would be appreciated. > Thank you, > Fred Kittelmann >
Fred, My best guess is that require is failing. See perldoc require for all the reasons that might happen, but the two most likely culprits are that your "modules" aren't in @INC or that they don't return a true value as their final statement. Try adding 1; to each of them as the last line of the file (again, read the require perldoc). Also add some more debugging code. require $ProgramName or die "$!\n"; would be a good start. Then you can examine $@ to see why the eval failed. HTH, -- jay -------------------------------------------------- Thanks Jay. I can't believe I didn't think of that myself. I put in the 1;'s and the "or die". It's not that the requires are failing - I get the same results. I added print $@; right after the eval block. Each time, that reads "The Unsupported function alarm function is unimplemented at line 5." What does that mean? Fred --------------------------------- Need a quick answer? Get one in minutes from people who know. Ask your question on Yahoo! Answers.