http://www.perlmonks.org?node_id=85515

harry_ has asked for the wisdom of the Perl Monks concerning the following question:

Dear perl-coders, Sorry if this question has been answered in the past. I am writing a program which checks the httpd version of random ip's (generated by the program). How can I can I make $0 move on to next ip, if no connection got established in a 5 sec wait? (I am not using IO::Socket) Sincerely yours, Harry.
  • Comment on How move on to next ip if no connection got established?

Replies are listed 'Best First'.
Re: How move on to next ip if no connection got established?
by Henri Icarus (Beadle) on Jun 04, 2001 at 22:59 UTC
    As long as you are on a unix system that handles signals you can use this:
    $seconds_allowed_to_do_task = 5; foreach (@list_of_things_to_do) { eval { local $SIG{ALRM} = sub { die "dead"}; alarm $seconds_allowed_to_do_task; &doTask($_); alarm 0; }; }
    The eval loop get's killed by the "die" after the alarm goes off (if it does). So just put your IP address in the list, and make doTask be the function that does your http connection. -Henri