おりょ?動くよ?
use strict; my $stop = 0; $SIG{"INT"} = sub { $stop = 1; print "sigint received\n"; }; while (1) { print "loop start\n"; sleep 3; if ($stop) { print "stop flag is true\n"; exit 1; } print "loop end\n"; }
こんな感じの出力:
daisuke@beefcake-7 ~$ perl hoge.pl loop start ^Csigint received stop flag is true daisuke@beefcake-7 ~$