in reply to RFC: Text::FixedWidth

One of the things I detest about fixed-length field parsers is that they require me to count characters (Either field width, or , worse, Start and end columns).

What I'd like to see is something that lets me paste-in a data sample, and mark field boundries using special characters, then allows me to name them. Something like:

# Sample Data ---- # FirstName Lastname YearBorn LastHaircutDate # I'd like to specify the above as: my $fields= " [irstName ][astname ][earBorn ][astHaircutDate ]"; my @fieldnames=qw( FirstName Lastname YearBorn LastHaircu +tDate); #Alternatively, allow optional TYPE specification with mixed hashrefs +and strings: my @fieldnames=( 'FirstName', 'Lastname', {name=>'YearBorn', +type='integer'}, {name='LastHaircutDate',type='date'});
I also like the idea of specifying the info using XML.

     "Income tax returns are the most imaginative fiction being written today." -- Herman Wouk

Replies are listed 'Best First'.
Re^2: RFC: Text::FixedWidth
by runrig (Abbot) on Feb 17, 2006 at 00:04 UTC
    My experience has been that most of the time, I would be given a document that specified the format in a "name length" or "name length start end" style, and I would cut and paste the document into Vim, do a couple of transformations, and have my module-ready format, which is why the format in the existing modules has worked for me 99% of the time. I can see the usefulness of your method, though, and it would be easy enough to preprocess your format into a something suitable for one of the modules, or just generate a pack/unpack format string (the only problem with your first idea that I can see is with fields that have names longer than their lengths).