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

I have a pipe (|) delimited .txt file & in the 5th position is the ssn. I want to read an Oracle table using the ssn & if the ssn is on the table I want to replace the 3rd postion in the .txt file with an ID from the same table. If the ssn is not on the table then do nothing. This seems simple but I've tried different ways with no success. Can anyone help?

Replies are listed 'Best First'.
Re: Replace a position in a txt file.
by davido (Cardinal) on Feb 04, 2014 at 22:38 UTC

    Which part is giving you trouble? Break it down into steps, and let us know which step you're unable to implement.

    • Read a line of a text file.
    • Obtain the 5th field from a line.
    • Search for the obtained value in your Oracle database table and if it exists, obtain the corresponding ID.
    • Write out the possibly updated line to a text file.

    I'm glossing over low level detail so that you can more easily point to the step that is problematic. Once we know which problem you haven't been able to solve, we will know where to provide help. And as you point to the part of the problem you haven't overcome yet, please provide a compact example of code that we can work on with you.

    One thing to keep in mind: Imagine you're doing this project with a pen and paper, and that you have no eraser or white-out. This is the situation that you mostly likely find yourself in when dealing with updating variable-width fields in a flat text file. If you were doing it with pen and paper, with no eraser and no white-out, you would take two pages of paper; one with your original information, and one blank. Then you would look at the first line of your original page, and write it down (with any necessary modifications) on the second page. You would repeat this line after line, until you have finished the new page. The new page would then contain a near duplicate of the original, but with the modifications in place. Once you verified that your new page is complete, you could toss out your original page. This is the most straightforward approach, and happens to be very close to how you will accomplish the task programatically as well.


    Dave

Re: Replace a position in a txt file.
by Kenosis (Priest) on Feb 04, 2014 at 22:38 UTC

    Can you show the code you've tried "...with no success"?