Thread: Perl reading Keyboard (q to exit)
hi all,
have program loops forever or until press ctrl+c. i'm wondering if possible watch q character or ctrl+c being pressed , exit program (i want delete temp files first , change colour of prompt back.)
many thanks,
sprouty
this example of how can catch ctrl^c , "q" entered on command line. function cleanup called when happens.
absolutely sure want catch ctrl^c? if code in cleanup goes wrong, can no longer interrupt ctrl^c.
code:# set new handler ctrl^c $sig{int} = \&cleanup; sub cleanup { # put code delete files , change prompt color here exit() } while($input = <stdin>){ # strip user input of newline chomp($input); # see if got quit command if ( $input eq "q") { cleanup() } # rest of perl script goes here }
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Perl reading Keyboard (q to exit)
Ubuntu
Comments
Post a Comment