in reply to Re^6: Parsing .txt into arrays
in thread Parsing .txt into arrays
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Parsing .txt into arrays
by Fshah (Initiate) on Jun 12, 2017 at 04:37 UTC | |
the problem I have is that there isn't just one table under a header ,there are multiple tables(of different sizes) under each header as shown, by observation I found out that the page (header+tables) ends only when we find year(2017) in the next line ,the position log here has 3 tables and each with its own header and it ends only when we see the next "2017" (Review log) PS: max tables in a page are 4. | [reply] [d/l] |
by Marshall (Canon) on Jun 13, 2017 at 01:52 UTC | |
There are many ways to express the idea that N tables belong to a single "record". Ultimately what you generate will need to be parsed and understood by something else. Can you explain more? Update: I think that the subroutine, finish_current_table() that decides which tables to "keep" would need to be modified. Perhaps with some state flag variable that indicates that we are within some 2017 year record? You keep talking about "pages". If you mean that these "pages" are separated by a form-feed (\f), that could potentially simplify the parsing situation. We could read an entire page at a time, then decide to keep or not the tables on that page? I personally don't like code or formats that depend upon "invisible" characters like \t or \f. But this could potentially be of help to simply the code. I am unsure. In any event, your code appears to be intended to transform a human understandable thing into a computer understandable thing. More detail about what this "computer understandable thing" is is appropriate. Update: with your extra example DATA: Read more... (7 kB) | [reply] [d/l] [select] |
by Fshah (Initiate) on Jun 14, 2017 at 10:06 UTC | |
hi Marshall, thanks for the reply and yes I need exactly what your code produces but with few changes, before that I want to let you know of what I'm doing or what output I'm expecting and what I want to do of it, I have a text file which is of format I've uploaded (although dummy data) this data pertains to some real time experiment I want to analyze this file using plots ,what I want perl to do is to remove these delimiters and extract particular type of pages and export it to a text file from where I'll use some other language (matlab) to parse this output file to extract some outputs. Back to the modification I need , the code prints all the tables (awesome) but I need only specific page and if possible I need each table into a different array (explanation followed)
Above is what your code produces but what I need is only(below) given the keyword Fp379
more over it would make my parsing easier if each of these tables would have different arrays, as I'm converting the header also as another field in the array e.g: a column with name "record start" and for a particular table all rows have same value under it sadly there isn't any form feed separating the pages there's a double blank line between pages but this is the same for few tables too, so I think end of the page can be found only by seeing the year in the next line(start of next page) One more important thing is that the program takes a lot of time to give out output considering the size of the file almost(1.5Gb), Will it not speed things up if we just read only the required pages won't it speed things up, its taking me more than 5 min to parse a single extension ,I'd desperately request you to suggest a way to reduce the time All I want is to look for a keyword and start printing all the headers + tables (as you are doing now ) until we find year name in the next line | [reply] [d/l] [select] |
by Marshall (Canon) on Jun 14, 2017 at 20:56 UTC | |
by marto (Cardinal) on Jun 14, 2017 at 11:57 UTC | |