Just a learner
Just a learner

Reputation: 28602

When reading input from the user in Perl, how to let Perl not display "Terminating on signal SIGINT(2)"?

I'm very new to Perl and currently I'm learning it on Windows 7 with ActiveState Perl. This is my program.

chomp(my @lines = <STDIN>);

foreach (sort @lines) {
    print $_;
}

When running the program, I type some lines of strings then press Ctrl + c to tell the program that I've finished typing. However, after I get my result (generated from print $_;), I also got this message: Terminating on signal SIGINT(2). How to disable this message?

Thanks.

Upvotes: 2

Views: 711

Answers (3)

Kharec
Kharec

Reputation: 68

You can handle signals like that:

$SIG{INT} = sub { print("Caught SIGINT but continue!\n"); };

for a keyboard interrupt. It's an exemple.

Upvotes: 1

perreal
perreal

Reputation: 98088

In Linux, press ctrl + D (EOF) instead of ctrl+C

Upvotes: 1

squiguy
squiguy

Reputation: 33380

For Windows, to signify End of Line press Ctrl + Z followed by Enter

Pressing Ctrl + C sends the interrupt signal to your program which is the cause of the Terminating on SIGINT message you are seeing.

Upvotes: 4

Related Questions