http://qs1969.pair.com?node_id=949448


in reply to Matching and combining two text files

OK, so thanks to GrandFather, I was able to take his code, tinker with it a bit, as I didn't quite understand a few things, and get a good routine going, working well, with one exception, it's repeating itself, it prints out each line of output about 4 times.

use strict; use warnings; my %docs; my $currParcel; my $file; my $line; my $doc; my $key; opendir(DIR, 'F:\project_files') || die $!; foreach $file (readdir(DIR)) { if ($file =~ /docs(.*)/) { $currParcel = $1; open(IN2, $file) || die $!; while(<IN2>) { chomp; $line = $_; $docs{$line} = $currParcel; } # end while } # end if } # end foreach close IN2; open(IN, 'carson_county_abstract.txt') || die $!; open(OUT, '>cars_abstract.txt') || die $!; while (<IN>) { $line = $_; if ($line =~ /Document #: ([0-9]*)(.*)/) { print $docs{$1} . "\n"; print OUT "parcel# $docs{$1} doc num $1 $2\n"; } # end if #print OUT "parcel# $docs{$1} doc num $1 $2\n"; } # end while close IN;

As you can see from the commented out print statement, I tried moving the print statement out of the if statement, but same problem there. Obviously the whole thing wouldn't work if it was moved out of the while loop, any thoughts on stopping the repeat?

At this point, I'm willing to put up with it, but I'm dealing with such a large data set, I really need to stop the repeating if I can..oO

...still no sleep...seeing little pink elephants holding syntax cue cards....