in reply to Best way(s) to process form data into fixed-length values?
IMO, the most convenient way to handle fixed-width records is with pack to write and unpack to read. Pack is usable either with arrays or lists of variables.
my @data = qr/foo bar bazaquuxinator/; my $format = q(A3 A10 A3 A35); my $line = pack $format, @data; print $line, $/; my $line = pack $format, @data[0,1], 'quux', $data[2]; print $line, $/;
That prints,
foobar baz foobar quubazaquuxinator $Unpacking with the same format string splits run-together items at the correct places. Notice that too-long data is truncated to the field width. The first printed line was constructed with not enough data for the format, so pack put 35 blanks at the end.
After Compline,
Zaxo
|
|---|