Perl-Sensitive Sunglasses | |
PerlMonks |
Unpack Many Fieldsby shoness (Friar) |
on Feb 15, 2010 at 23:38 UTC ( [id://823371]=perlquestion: print w/replies, xml ) | Need Help?? |
shoness has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I've a file containing ~20k lines of ASCII data. Each line has about 170 fields. I care about ~30 fields, scattered throughout each line. On each line, data is not delimited. Each field is of fixed width. The first field on each line is unique (their destiny to become my hash key). Speed is not a factor, but it seems "unpack" may be the best choice. In my initial implementation, I've never coded anything so ugly as this. The line with the format specifier is almost 400 characters long. Yuk! My second implementation used the document that specified the width to automatically build up the format string and grab the names of the fields: It was not significantly better because I still need to know the number of fields in order to built the left-hand-side and now I've got another file to parse, etc. I'm really missing something. If I used the regexp engine with /g, I could programmatically walk down each line pulling out the fields I want. I'm just not sure here...other than that I must be missing something. Your advice is GREATLY appreciated!
Thanks!
Back to
Seekers of Perl Wisdom
|
|