----- Original Message ----- 
From: Chris Rodriguez
.
.
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 or die "Require failed\n";
      alarm 0;
  };
  print $@;
  if($@) {
    if($@ =~ /timed out/) {
      print "timeout\n"; # timeout
    } else {print "some other error\n"; # some other error
   }
  }
}

If the alarm function now works on Windows, why doesn't this code give me 
the results I expect?  Might it matter than I'm using Windows ME?  What 
about my version of PERL?  It's the one from the CD that came with that 
book.  5.6 I think - I can check if it matters.

###########################################

I think it does matter. I didn't check to see what happens when I try to run 
the above code on perl 5.6 (though I expect it fails), but there's certainly 
no problem with that on perl 5.8.8.

I created 4 scripts along the lines you suggested, and ran the following 
(slightly modified version of your) code:

-------------
use warnings;

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 or die "Require failed\n";
      alarm 0;
  };
  print "Error message: *** $@ ***\n";
  if($@) {
    if($@ =~ /timed out/) {
      print "timeout\n"; # timeout
    } else {print "some other error\n"; # some other error
   }
  }
}
--------------

For me that outputs:

--------------
C:\_32\pscrpt>perl try.pl
Error message: ***  ***
Error message: ***  ***
Error message: *** infinite3.pl timed out
Compilation failed in require at try.pl line 8.
 ***
timeout
Error message: ***  ***
--------------

The first 2 lines of output appear almost immediately, and the rest appears 
9 seconds later.

That's pretty much as expected. However, I wasn't expecting that 
"Compilation failed in require at try.pl line 8.\n" would be concatenated 
onto "infinite3.pl timed out\n". On further reflection, I *think* it's 
correct and expected behaviour ... but I'm not necessarily right about that 
aspect :-)

Certainly, if you comment out that SIGALRM handler subroutine, then the 
output is as expected:

--------------
C:\_32\pscrpt>perl try.pl
Error message: ***  ***
Error message: ***  ***
Terminating on signal SIGALRM(14)
--------------

Again, the first 2 lines appear instantly, the third 9 seconds later.

I recommend you switch to the latest perl - you can get it from:
http://activestate.com/store/download.aspx?prdGUID=81fbce82-6bd5-49bc-a915-08d58c2648ca

And yes, I *am* running in what's commonly referred to as the DOS shell - 
though it's actually the cmd.exe shell (which has nothing to do with DOS).
Which shell are you using ?

Cheers,
Rob



_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to