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

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

Hello PerlMonk.

I have console perl program that connects to database, checking records every 30 seconds, and if data has changed it should do it's job. With ctrl + c, I want this program to disconnect from database, so I tried SIGINT signal handler even though Chapter 4 of "Advanced Perl Programming" warned me the trouble of Win32 signal. My program shows no response to ctrl + c while sleeping 30 seconds and this is my problem.

So far, I have read through previous threads, SOLVED Perl SIG INT handling conundrum. , GOTO, Signals and Win32 , and especially this one win32, ctrl-c, sleep, and signals .
"set PERL_SIGNALS=unsafe" gives me quick response but it yields fatal error dialog saying perl has crashed. I am using perl 5.12.1 of Win32 IndigoAMPP package. Below is my sample code.
use strict; use warnings; #this doesn't work #$ENV{PERL_SIGNALS} = "unsafe"; local $SIG{INT} =sub { print "in SIGINT ...exitting\n"; #here I want disconnect from database; exit; }; while (1){ print "in while loop\n"; sleep 30; #this is what I can do best so far... #sleep 3 for (0 .. 10); }
I am glad with any advice.