ddrew78 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I don't even know where to begin this one. Basically, I have four files, file6, file8, file11 and file13. Below I have a sample of the content of the files.

file6
abc-def 2000 abc-def 2007
file13
abc-def 3 abc-def 95 abc-def 1300 abc-def 2000 abc-def 2001 abc-def 2002
file8
abc-def 2000 sometext abc-def 2000 sometext abc-def 2007 sometext abc-def 2007 sometext
file11
abc-def 2000
What I need to do is find duplicate entries between file6 and file13 (already done, shown in file11), and replace that number in file8 with a number from a pre-defined range that is not used in file13. I'm not sure if I even need to pull the duplicate numbers into a separate file or not. Also, the 'abc-def' string does stay the same in all files.
I know I've posted a few questions on here before, but I'm new to perl and am trying to learn on the fly. Any ideas would be greatly appreciated.

Replies are listed 'Best First'.
Re: replace data based on duplicate in another file
by moritz (Cardinal) on Apr 03, 2009 at 14:11 UTC
    Use split to split the records, and store them in hashes. Then when you process the next file, look into you hash to see if that key has already been encountered.

    With this scheme you can solve (nearly) all the "find duplicates", "remove duplicates" and "replace duplicates" problems.

Re: replace data based on duplicate in another file
by lakshmananindia (Chaplain) on Apr 03, 2009 at 14:08 UTC

    It would be nice if you post what you have tried so far. Try to explain what you have done and in what area you are experiencing problem

    --Lakshmanan G.

    The great pleasure in my life is doing what people say you cannot do.


Re: replace data based on duplicate in another file
by apl (Monsignor) on Apr 03, 2009 at 16:15 UTC
    If you were doing it by hand, what would be the steps you'd take? If you already know how to program, what would the program look like?

    If you can outline the logic, writing the program is trivial. OTOH, if you don't know how to solve the problem, you can't write the program.