I got bored and wrote something that'll parse your data and even figure out the format on-the-fly. Just be sure no headings have spaces in them. Leading and/or trailing whitespace in each field is left intact, so you'll have to trim that on your own if you need to. (Note that I've expanded upon this code here:
Parse fixed-length ascii table)
use Data::Dumper;
my (@keys, $format, @data, @sizes);
$_ = <DATA>;
while (/\G(\S+)\s+/g) {
push(@keys, $1);
push(@sizes, $+[0]-$-[0]);
}
$format = join("", map { "a$_" } @sizes);
while (<DATA>) {
# if you want a hashref for each line:
my $i;
push(@data, { map { ($keys[$i++], $_) } unpack($format, $_) } );
# else, take out references to @keys above and just use this:
push(@data, [ unpack($format, $_) ] );
}
print Dumper(\@data);
__DATA__
Name ID PS Gender Age Month Code
+ Cap Pool
LName, FName 99999 99 M 99.9 12/2000 Add
+ 99.99 99.99
Have fun.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.