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


In reply to GOTO, Signals and Win32 by kakaze

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.