Moritz: (and others) Thanks for your advice.
As for reading the new "clean" file in by blocks (as that is what I think you are suggesting), that would be great. The "cleaning" of the first file puts the "END-OF-DOCUMENT" record divider at the end of each record, whereas "h4>Award\s\#\d+<\/h4" is the start of the record, so it should work. But I am a bit confused (my Perl skills are not up to par). Do I need to modify other parts of the document? By just adding
local $/ = 'END-OF-DOCUMENT', the program no longer parses the data from the records. Should it still be using the new clean document with <IN>, but now only reading a record at a time, as such:
open(OUT, ">/Users/micwood/Desktop/output.txt");
while (<>) {
s/\r//g;
s/\t//g;
s/(<h4>Award\s\#\d+<\/h4>)/\nEND-OF-DOCUMENT\n$1/g;
s/(<!-- \/noindex --><\/font>)/\nEND-OF-DOCUMENT\n$1/g;
print OUT "$_";}
close OUT;
my $novalue = '.'; # temp value
my $temp = '.'; # temp value
my $awardhashref= ();
open (IN, "/Users/micwood/Desktop/output.txt");
open(OUT2, ">/Users/micwood/Desktop/output2.csv");
my $allDocs = do
{
local $/ = 'END-OF-DOCUMENT';
<IN>;
};
my $rxExtractDoc = qr
{(?xms)
(<h4>Award\s\#(\d+)<\/h4>(.*?)END-OF-DOCUMENT)
};
while ($allDocs =~ m{$rxExtractDoc}g )
{
my %award = (); # award hash
$award{'entireaward'}= $1;
$award{'A_awardno'}= $2;
$award{'entireaward'}=~ s/\n//g;
if ($award{'entireaward'} =~ m{Dollars Obligated<\/td><td align=
+right>\$([^<]+?)<\/font>}gi){
$award{'B_dollob'} = $1};
etc, etc
Which is fine, as long as it doesn't read the entire new "clean" file as once since I don't think memory could handle that. But if all I need to do is add
local $/ = 'END-OF-DOCUMENT', any clue why it no longer works?
Thanks again, and I hope my questions are too simple (just not very good at this).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.