rerunn has asked for the wisdom of the Perl Monks concerning the following question:
I have a problem which I have been struggling with and have basically been running in circles trying to solve it.
I have 2 files, (file_A and file_B) consisting many lines of records. Each record is in this format:
field_1:field_2:field_3:field_4:field_5
What i need to do is take file_A and compare field_1 in each line with field_1 in file_B. If an occurence of field_1 does not exist in file_B, I must remove the line from file_A.
This first part was simple enough -- I made a hash of arrays. field_1 was the key and the whole line was the array/value. I then compared the keys in each array to yank out the lines. So this leaves me %file_A with the correct lines taken out. What I need to do next is take this %file_A and then do the same thing with field_4. I attempted loop through %file_A comparing field_4 in the array with its counterpart in %file_B. It worked but was painfully slow. There must be a better way. There is also a file_C involved and this involves only keeping the lines in file_A that dont have the corresponding field_3 value -- I can wait till I figure out the first one.
Hopefully someone didnt get painfully confused enough to answer my question :)
Thanks and warm regards,
rerunn.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash jerkin
by BrowserUk (Patriarch) on Feb 12, 2003 at 03:59 UTC | |
|
Re: hash jerkin
by Cabrion (Friar) on Feb 11, 2003 at 23:49 UTC | |
by Fletch (Bishop) on Feb 12, 2003 at 04:36 UTC | |
|
Re: hash jerkin
by mikezone (Novice) on Feb 11, 2003 at 23:49 UTC | |
|
Re: hash jerkin
by steves (Curate) on Feb 12, 2003 at 02:36 UTC | |
|
Re: hash jerkin
by JamesNC (Chaplain) on Feb 12, 2003 at 05:11 UTC |