in reply to Re^2: Google has failed me! Using pack and substr for fixed width file output
in thread Google has failed me! Using pack and substr for fixed width file output

There are all kinds of interesting games you can play with pack, and it should be easy to encapsulate your solution in a function (with lotsa validation) so that maintainers only see data. See below.

Note that the  @ pack template specifier fills with nulls, so if you want space-filling, you need the
    $packed =~ tr{\000}{ };
statement. Note also that  @ is absolute, so maybe play around and see, e.g., what happens if the  date offset is set to 1 or 2.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "use constant ORDER => qw(date client_id info); ;; my %o_l = ( date => { qw(off 0 len 6 field 040814) }, client_id => { qw(off 6 len 8 field WayTooMuchClientID) }, info => { qw(off 20 len 7 field G1APD) }, ); ;; my $fields = join ' ', map qq{\@$o_l{$_}{off} A$o_l{$_}{len}}, map { exists $o_l{$_} or die qq{bad '$_'}; $_; } ORDER ; ;; my $packed = pack $fields, map $o_l{$_}{field}, ORDER; $packed =~ tr{\000}{ }; print 'packed len ', length $packed, qq{ '$packed'}; ;; my $total = 30; die 'truncation!' if length($packed) > $total; my $line = pack qq{A$total}, $packed; print 'total len ', length($line), qq{ '$line'}; ;; dd \$line; " packed len 27 '040814WayTooMu G1APD ' total len 30 '040814WayTooMu G1APD ' \"040814WayTooMu G1APD "