Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Google has failed me! Using pack and substr for fixed width file output

by runrig (Abbot)
on Apr 08, 2014 at 21:08 UTC ( [id://1081570]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1081570]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found