in reply to 2 Hash Tables, 4 Keys...what to do?

In file1, is word1..word4 unique (only 1 line has any specific word1..word4)? Is it feasible to read in the whole file? If so, my approach would be something like:
my %file1; while (<FILE1>) { # Capture first four words, and everything after the next 3 words +(numbers) my ($k1, $k2) = /(\w+(?:\s+\w+){3})(?:\s+\w+){3}(.*)/; # Index by k1, store k2 and line $file1{$k1} = [$k2, $_]; } while (<FILE2>) { my ($k1, $k2) = .... # same regex as before if ($file1{$k1}) { # print file1 line and file2 line print $file1{$k1}->[1]; print; # Check if k2's are equal if ($file1{$k1}->[0] ne $k2) { print "K2's are not equal! (see lines printed above)\n"; } } }
I've probably misunderstood some of what you want, but I think the parsing of the keys could be a significant help to you.

Update: fixed regex as per nobull's note.


Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: 2 Hash Tables, 4 Keys...what to do?
by nobull (Friar) on Jun 03, 2005 at 16:43 UTC
    /((\w+(?:\s+\w+){4})(?:\s+\w+){3}(.*)/;
    I think you meant
    /(\w+(?:\s+\w+){3})(?:\s+\w+){3}(.*)/;