cztmonk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,I have the following code. I want to handle Ctrl-C when waiting for $choice
# Handle Ctrl-C $SIG{INT} = \&ctrlc; use autodie; use Modern::Perl; use Storable qw {store retrieve}; my $dbfile = 'sbs.db'; my %person = %{ retrieve($dbfile) }; while() { print "\n(C)reate,(L)ist,(N)ew,(M)odify,(R)emove,(Q)uit? "; chomp(my $choice = <>); $choice = lc $choice; # # Some code here # } exit; sub ctrlc { store \%person,$dbfile; print "You used Ctrl-C!"; exit 1; }
When I press Ctrl-C, I get the following messages :
(C)reate,(L)ist,(N)ew,(M)odify,(R)emove,(Q)uit? Use of uninitialized v +alue $choice in chomp at J:\ps \monks.pl line 13. Use of uninitialized value $choice in lc at J:\ps\monks.pl line 14. You used Ctrl-C!
How can I avoid the error messages? And have a clean exit?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Handle Ctrl-C on Windows
by marto (Cardinal) on Aug 28, 2012 at 10:32 UTC | |
|
Re: Handle Ctrl-C on Windows
by jethro (Monsignor) on Aug 28, 2012 at 09:49 UTC | |
by cztmonk (Monk) on Aug 28, 2012 at 10:14 UTC | |
|
Re: Handle Ctrl-C on Windows
by philiprbrenan (Monk) on Aug 28, 2012 at 11:49 UTC | |
by cztmonk (Monk) on Aug 29, 2012 at 06:54 UTC |