in reply to Custom interrupt?

You seem to be suggesting that different entries may have different numbers of fields to be entered. How is the true field count determined for a given entry, and where to the field labels come from? (In your example, there are just two fields per entry, with the labels "id" and "comments".)

You also seem to want the user to be able to write incomplete entries, escaping out of the field-entry loop with only one or more of the initial fields filled in, and one or more of the final fields in the sequence left undefined (null), and these get written to the database file along with complete entries.

I think what you might want here is a subroutine that takes two array refs, one containing the field labels and the other containing prompt strings, with both arrays ordered according to the desired sequence for user input; the sub would return a hash with field labels as keys and user input as values. Whatever is returned by the sub can then be written to the database. Something like this (not tested):

sub entry_prompter { my ( $labels, $prompts ) = @_; my %entry; for my $i ( 0 .. $#$labels ) { my $user_input = prompt $$prompts[$i], -escape; last if ( $user_input eq "\e" ); $entry{$$labels[$i]} = $user_input; } return %entry; }
WIth that, it's up to the caller to set up the appropriate arrays, handle the iteration that prompts for "Add another entry? y/n: ", and read/write the database file.

If I were you, I'd add another array that provides conditions for sanity checks on the fields, so that the "entry_prompter()" sub can test $user_input -- e.g. should be numeric, or "y/n", or not longer than 10 characters, or whatever.

Then again, if I were you, I'd use a real database (not a flat file), and I'd use Tk; to provide a nice GUI with appropriate user input widgets to fully populate a record as efficiently and reliably as possible, along with a "Submit" button.

(updated to simplify some of the wording in the text)

Replies are listed 'Best First'.
Re^2: Custom interrupt?
by azredwing (Sexton) on Jul 03, 2008 at 05:56 UTC
    It's a very good point you bring up. I'm actually using Text::CSV_XS and using the print method to print the arrayref. The reason why I'm doing this is because other programs have to interact with the CSV files.

    I'm keeping two different databases for information about receiving images: one for partial images, one for missing images. (I don't want to get into more one-off detail, but I will say that this is in support of the Phoenix Mars Lander...) Depending on the database you're manipulating, there could be 5 or 8 different fields, and the process is always evolving.

    I would write a GUI for this but quite frankly I don't know how. I taught myself Perl a few months ago to get my job done effectively, so what I've been doing is pretty quick and dirty.