Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: creating array of hashes from input file

by chimiXchanga (Novice)
on Mar 08, 2017 at 06:38 UTC ( [id://1183920]=note: print w/replies, xml ) Need Help??


in reply to Re: creating array of hashes from input file
in thread creating array of hashes from input file

that looks beautiful! may I kindly ask, would this layout would be an easier an approach to parse? And if so, how would you approach joining the data on the next line to the proper column?
100 Civic Center Way + Page 1 of 3 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 Upgrade panel fr +om 100 amp to 200 amp DR 06/04/2012 24956 NORMANS (6) light fixtur +es @ patio; (3) branch circuits; (4) electric heaters WAY 06/05/2012 4273 VICASA Construct 339 SF + Covered Loggia DR 06/07/2012 26011 ALIZIA CANYON R/R (1) <100K BT +U Furnace in garage; () <100K BTU condenser outsid +e (NO DUCTS TO BE CHANGED OUT) DR E 06/07/2012 4240 LOST HILLS R/R (7) windows +(like for like) AT LEAST ONE PANE MUST BE TEMPERED RD 1503 06/08/2012 3574 ELM Construct Retain +ing Wall in front of (E) retaining wall: 4 1/2' average x 3 +2 LF = approx. 144 SF DR 06/13/2012 4026 TOWHEE Construct a 460 +SF Pool/49 SF Spa DR

Replies are listed 'Best First'.
Re^3: creating array of hashes from input file
by poj (Abbot) on Mar 08, 2017 at 07:46 UTC
    would this layout would be an easier an approach to parse

    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.

    #!perl use strict; use Data::Dumper; my $infile = 'report1.txt'; # date address description my $fmt = "A16 A38 A*"; my @data = (); my $recno = -1; my $flag = 0; open IN,'<',$infile or die "$infile $!"; while (<IN>){ chomp; next unless /\S/; $flag = 0 if /Page \d of \d/; my ($date,$addr,$desc) = unpack $fmt,$_; if ( $date =~ /\d\d.\d\d.20\d\d/ ){ $flag = 1; ++$recno; $data[$recno] = [ $date,$addr,$desc ]; } elsif ($flag) { $data[$recno][1] .= ' '.$addr if $addr; $data[$recno][2] .= ' '.$desc if $desc; } } close IN; print scalar(@data)." records read\n"; print Dumper \@data;
    poj
Re^3: creating array of hashes from input file
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1183920]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found