kakaze has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I am trying to do the following:
Step through a foreach loop and call a funtion.
The function may take a very long time to complete but I only want to wait a finite period of time and if the function has not completed, go to the next iteration of the loop.
I am using an alarm() with a call to a signal handler in order to acomplish this.
My problem is that when I try to use a goto withing the signal handler, I get the following error:
Can't find label LABEL at ./t21.pl line 18.
I should mention that I running this in a Win32 (Win 2K) machine and I am aware of all the caveats that apply to signal handling on this OS.
Aparently the alarm() call is now supported on Win32 for Active State Perl 5.8.0. which I am using(See article here) and it appears to work fine.
Here is my code:
sub callfc() { # just keep printing until the signal goes off for ($i = 0; $i < 1000; $i++) { print "$i \n"; sleep(1); } } for ($j = 0; $j < 1000000; $j++) { # set signal time out alarm(2); # set up signal handler $SIG{ALRM} = sub { goto "LABEL"; }; # call the function &callfc(); LABEL: # hopefully skip to the next iteration of the loop } print "I am continuing with the code\n"; sleep(1); print "I am continuing with the code\n";
for the test code above, I've used a simple for loop but the same principle applies.
Does anyone have any suggestions on how to acomplish what I am trying to do, either with the (much frowned upon goto) or any other way.
Thanks for your help!
Kakaze
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: GOTO, Signals and Win32
by broquaint (Abbot) on Nov 14, 2003 at 11:48 UTC | |
by kakaze (Sexton) on Nov 14, 2003 at 13:11 UTC | |
by Zarabozo (Sexton) on Dec 08, 2024 at 21:05 UTC | |
by LanX (Saint) on Dec 08, 2024 at 21:13 UTC | |
by kakaze (Sexton) on Nov 14, 2003 at 12:42 UTC | |
by kakaze (Sexton) on Nov 14, 2003 at 13:15 UTC |