[Melbourne-pm] eval

Brendon Oliver brendon.oliver at gmail.com
Thu Oct 27 21:25:03 PDT 2005


On Friday 28 October 2005 14:08, Ryan Tan wrote:

> I'm trying to, in this code, say if the execution of takes more than
> 60 seconds, to kill it and start again.
>
> I still need to notice the death and press ^C.
>
> I am using W32... would this be easier under linux (and use fork
> etc).
>

You need "die" in your signal handler, not warn.  Try it this way 
(untested, but based on some code I _have_ used before):

>         for (my $a=0; $a<10000;$a++)
>         {
		eval {
			local $SIG{ALRM} = sub { die "TIMED_OUT" };
>                 
>                         alarm(60);
>                         &main;
>                         alarm(0);
		};

		if ( $@ eq "TIMED_OUT" ) {
			# ...handle time out 
			# "next" if you want the next step thru the loop
			# or "last" if you want to bail out...
		}
		else {
			# something wicked happened!
			die "$@\n";
		}
>         }

Cheers,

- Brendon.
-- 
 _____________________________________ 
/ The reward for working hard is more \
\ hard work.                          /
 ------------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


More information about the Melbourne-pm mailing list