I recently had the opportunity to work with text files containing fixed-width data. I wrote a function to implement this, and I'm wondering if people would find a module helpful.
Some sample usage:
use Text::FixedWidth; my @fields = ( { field => name, from => 1, to => 5 }, { field => email, from => 8, to => 25 }, ); my $fw = Text::FixedWidth->new( fields => \@fields, ); $data_ref = $fw->parsefile('data.txt');
$data_ref would look like:
$data_ref = [ { name => 'Bob', email => 'bob@email.com' }, { name => 'Sam', email => 'sam@mail.com' }, ];
It basically parses each line of the file into a hashref with column names as keys. You need to define your column names and their from and to positions in the line, or alternately specify the width directly.
If interested, I can supply more info, but the above code mostly says whats in my head right now.
Thanks!
In reply to RFC: Text::FixedWidth by arc_of_descent
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |