Your problem arises when some fields are not filled in, so their names don't show up at all in the form submission -- you have to know what they are in advance of receiving a given submission, so that you can figure out when they are missing.
So, given that there is a finite, maximum set of fields as defined by the complete form, you should change this line in the OP code:
to be something like this:@FieldNames = sort (keys %FORM);
where each "FieldnameN" represents an actual name of a parameter key coming from the form, the array contains the complete set, and the names are in the desired order for printing to the log file.@FieldNames = qw/Fieldname1 Fieldname2 Fieldname3 .../;
Then your loop over the key names would go something like this:
though personally I prefer concatenating fields into a line string, and printing the line:foreach $key (@FieldNames) { my $val = ( defined( $FORM{$key} ) and $FORM{$key} =~ +/\S/ ) ? $FORM{$key} : "BLANK"; print LOGFILE "\t$val"; }
Note that the "defined()" check is simply there to avoid warnings about string operations on undefined values, in case you happen to have "-w" or "use warnings" in your script (which is generally a good idea). Then the regex match allow any value containing non-whitespace to get into the log file.my $line = ''; foreach $key (@FieldNames) { $line .= "\t" . ( defined( $FORM{$key} ) and $FORM{$ke +y} =~ /\S/ ) ? $FORM{$key} : "BLANK": } print LOGFILE "$line\n";
In reply to Re^3: Add Null values to my FlatFile
by graff
in thread Add Null values to my FlatFile
by lakeTrout
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |