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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RFC: Text::FixedWidth
by friedo (Prior) on Jul 25, 2005 at 22:39 UTC | |
by arc_of_descent (Hermit) on Jul 25, 2005 at 22:45 UTC | |
|
Re: RFC: Text::FixedWidth
by runrig (Abbot) on Jul 25, 2005 at 23:22 UTC | |
by arc_of_descent (Hermit) on Jul 26, 2005 at 09:28 UTC | |
|
Re: RFC: Text::FixedWidth
by NetWallah (Canon) on Jul 26, 2005 at 17:06 UTC | |
by runrig (Abbot) on Feb 17, 2006 at 00:04 UTC | |
|
Re: RFC: Text::FixedWidth
by pg (Canon) on Jul 26, 2005 at 07:22 UTC | |
by runrig (Abbot) on Jul 26, 2005 at 22:07 UTC |