chimiXchanga has asked for the wisdom of the Perl Monks concerning the following question:
Page 1 of 3 100 Civic Center Way Calabasas, California 91302 7/12/2012 9:21:02AM MONTHLY EXTERNAL MODIFICATIONS PERMITS REPORT Jun 2012 Permit Issued Address Description 06/01/2012 26166 ROYMOR DR Upgrade panel from 100 amp to 200 amp 06/04/2012 24956 NORMANS WAY (6) light fixtures @ patio; (3) branch circuits; (4) electric heaters 06/05/2012 4273 VICASA DR Construct 339 SF Covered Loggia
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: creating array of hashes from input file
by Eily (Monsignor) on Mar 07, 2017 at 13:42 UTC | |
I can't think of a proper way of capturing just the data I needFirst remove the data you don't need, et voilą! You'll have to be more specific than that, we can't guess what is useful information for you. I can't even understand how you're supposed to read your data. See How do I post a question effectively? Be aware that you shouldn't expect to be given a fully functional solution, but rather advice, and maybe corrections. So you'll have to show some work. | [reply] |
Re: creating array of hashes from input file
by Corion (Patriarch) on Mar 07, 2017 at 13:49 UTC | |
My approach when parsing lists depends on the nature of the list. If I can find out from looking at a single line what kind it is, then I use regular expressions to fill out a hash and flush the record whenever a new set starts. If I can't find out from looking at a single line what kind it is, I use counters or flags to know what line I am on. In your case, it looks to me as if you basically have a report with some header data and then three payload lines, the issuance date, the address and the description. One ugly thing seems to be that the address and the permission can span multiple lines, but from the unrepresentative example you have posted, each item seems to be delimited by a blank line from the previous item. Going from these assumptions, my approach would be something like the following (untested):
| [reply] [d/l] |
by chimiXchanga (Novice) on Mar 08, 2017 at 06:38 UTC | |
| [reply] [d/l] |
by poj (Abbot) on Mar 08, 2017 at 07:46 UTC | |
Maybe, depends on what pages 2 and 3 are like. Are you parsing many reports all formatted the same ?. Or is the 3 pages just a small sample of the real report. poj | [reply] [d/l] |
by Corion (Patriarch) on Mar 08, 2017 at 08:49 UTC | |
Here, instead of a regex I would likely use unpack with the appropriate template(s). Append to %info until you encounter an empty line, then flush. | [reply] [d/l] |
Re: creating array of hashes from input file
by huck (Prior) on Mar 07, 2017 at 23:37 UTC | |
Corion made good points, but it needs a flush(\%info); at the end. Here is a more non form dependent single state driven method. I like state machines too! It also fixes some common excel problems noted.
| [reply] [d/l] [select] |
by huck (Prior) on Mar 08, 2017 at 02:33 UTC | |
I played with the above so much i factored out the array of hashs to make the output file instead after putting it in, So the following is refactored again to construct the AoH, THEN make the output file from it.
| [reply] [d/l] |