in reply to Google has failed me! Using pack and substr for fixed width file output

What I might do (but using your actual list of fields and helpful/descriptive names for each field) using Parse::FixedLength:
use Parse::FixedLength; my $pfl = Parse::FixedLength->new([qw( name:10 date:6 filler:10 )]); my %hash = ( name => 'Joe', date => '020414', ); my $str = $pfl->pack(\%hash); print "[$str]\n"; $hash{name} = 'Bob'; $str = $pfl->pack(\%hash); print "[$str]\n"; # Or even: use Parse::FixedLength; my $pfl = Parse::FixedLength->new([qw( name:10 date:6 filler:10 )], {href => \my %hash} ); %hash = ( name => 'Joe', date => '020414', ); my $str = $pfl->pack(); print "[$str]\n"; $hash{name} = 'Bob'; $str = $pfl->pack(); print "[$str]\n";
  • Comment on Re: Google has failed me! Using pack and substr for fixed width file output
  • Download Code