Takkun
Takkun

Reputation: 6381

Try/Catch Keyboard Interrupt in Perl?

How can I catch a keyboard interrupt in Perl?

while(1) {
    try {
        print 1;
    } 
    catch KeyboardInterrupt {
        print 2;
    }
}

Upvotes: 2

Views: 779

Answers (1)

LeoNerd
LeoNerd

Reputation: 8542

You appear to be trying to write Python here.

"Keyboard interrupt", most likely means SIGINT. You can handle signals using the %SIG hash. For example:

$SIG{INT} = sub { print "Received SIGINT\n" };

Upvotes: 6

Related Questions