The thing is, the user needs to be able to quit data entry and go back to do other things by hitting the ESC key. I can't just return out of the add_to_db() subroutine without first doing a write_to_db() first.
What I've been doing thus is:
For entries that have lots of fields, it gets unwieldy to write out that return if "\e" statement. I wrote a subroutine "clean_return" that writes the database to a file when called, but that doesn't change the fact that I can have up to 16 different return-if-ESC statements.my @database = read_from_db(); while (1){ my $id = prompt "Enter the product ID: ", -escape; return write_to_db($database_type, @database) if $id eq "\e"; my $comments = prompt "Enter any comments about this product: ", - +escape; return write_to_db($database_type, @database) if $comments eq "\e" +; print "Confirm the following data:\n"; print "Product ID: $id\n"; print "Comments: $comments\n\n"; my $yn = prompt "Is this information correct? y/n: ", -yn; #no esc +ape here since this info will get lost if we escape redo if ! $yn; push(@database, [$id, $comments]); $yn = prompt "Add another entry? y\n: ", -yn, -escape; last if !yn || $yn eq "\e"; } write_to_db($database_type, @database);
What I want to do is set up an interrupt-type thing: so if at any time the ESC key is pressed, it should do a clean_return. This way I only need to write that out the one time instead of up to 16 different explicit clean_return statements.
If you could help me out, I'd greatly appreciate it. Thanks.
In reply to Custom interrupt? by azredwing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |