in reply to Re^2: Best way(s) to process form data into fixed-length values?
in thread Best way(s) to process form data into fixed-length values?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Best way(s) to process form data into fixed-length values?
by johngg (Canon) on Jul 25, 2006 at 22:42 UTC | |
by GrandFather (Saint) on Jul 25, 2006 at 22:52 UTC |