hmbscully has asked for the wisdom of the Perl Monks concerning the following question:
I have an obnoxious online form that gathers upto ~150 user-supplied values. I need to process these values and build a fixed-length record from them. I've been thinking of half a dozen ways to deal with the data, so I thought I'd ask some wise monks to add to the list of how to do handle them.
I've not worked with creating fixed length records before, but I realize that sprintf() is going to be my friend. What I'm trying to figure is a decently efficient way to handle the fact that many of the fields of the record may be submitted empty, which is fine, but I have to make sure they're holding the right amount of spaces in the final record.
Should I declare all the variables up front something like
my $zip_1 = " "; #12 spaces etc? and then have the variable values updated when I get the values from the form if there is a submitted value for that form?
I have several groups of variables that all need to be the same lengths. 35 is a popular length. After I read in the data from the form, say
$addressee_1 = param('addressee1'); and so on and so forth... can I assign all the variables that need to be 35 characters in length to an array and then foreach the whole array with a $foo = sprintf("%-35s", $foo);? Or are those variable changes local to the array? What I mean, is can I reference those variables later just as $addressee_1 and get the variable with the change, or do I have to reference them as part of the array (my array syntax sucks and I can't think of it at the moment) to get the padded/truncated value?
Vague enough? I welcome any questions to help me clarify my thinking. Thanks!
|
|---|