Marcello wrote: > Manav Mathur ha scritto: > >>> Hi all, >>> I have a text file with columns, where the columns may not be aligned, >>> and not all lines may have data in all columns: >>> >>> header1 header2 header3 header4 >>> ------------------------------------------------------------ >>> l1dat1 l1dat2 l1dat3 l1dat4 >>> l2dat1 l2dat4 >>> l3veryveryveryverylongdat1 l3dat2 >>> >>> As you can see, line1 has all data, line2 is missing clomuns 2 and 3, >>> line 3 is a mess :) >>> >>> Any thoughts on parsing such a "table"? >>> Please don't offer solutions suggesting to change the way the text >>> file is written, I have no control over that... >>> >>> Regards, >>> -- >>> Offer Kaye >> >> >> >> How do you logically determine that "l2dat4" in line 2 is column 4 and >> not >> column 2?? >> >> Manav >> >> >> > > Just a thought: because l2dat4 starting column is greater than column 4 > header starting column ? > > Marcello >
That still falls apart on line 3, because l3dat2 which is "actually" column 2 starts after header3's initial position. Though in that case I guess you might be able to determine that it is column two because there aren't two spaces, but that is still using the assumption that there *must* be at least one space character delimiting columns. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>