azredwing has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Custom interrupt?
by graff (Chancellor) on Jul 03, 2008 at 04:22 UTC | |
by azredwing (Sexton) on Jul 03, 2008 at 05:56 UTC | |
|
Re: Custom interrupt?
by jethro (Monsignor) on Jul 03, 2008 at 04:25 UTC | |
|
Re: Custom interrupt?
by pc88mxer (Vicar) on Jul 03, 2008 at 04:55 UTC | |
|
Re: Custom interrupt?
by pc88mxer (Vicar) on Jul 03, 2008 at 05:40 UTC | |
|
Re: Custom interrupt?
by TGI (Parson) on Jul 04, 2008 at 00:59 UTC | |
by azredwing (Sexton) on Jul 06, 2008 at 06:16 UTC |