You could toss the various values into arrays. Something tht may help is:
use warnings; use strict; my @fields; my $fieldValue = 'Grand'; # Given name field contents push @fields, [$fieldValue, 10]; # 20 character wide field $fieldValue = 'Father'; # Sir name push @fields, [$fieldValue, 10]; # 25 character wide field push @fields, ['007 Bond Street', 15]; push @fields, ['Wibble Wobble', 15]; push @fields, ['', 15]; push @fields, ['Erewhon', 15]; #... my $record = join '', map {sprintf "%-*.*s", $_->[1], $_->[1], $_->[0] +} @fields; print $record;
Prints:
Grand Father 007 Bond StreetWibble Wobble Erewh +on
which ties the field size to the field contents at the point where the contents are added to the field list then uses the field size to control field width in a sprintf later on.
In reply to Re^3: Best way(s) to process form data into fixed-length values?
by GrandFather
in thread Best way(s) to process form data into fixed-length values?
by hmbscully
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |