in reply to How to compare a field in 2 files and set a value if it matches?

The words 'It doesn't work' aren't generally the best ones to use when attempting to precisely define your problem :), but it looks like the *main* problem here is that your 'read the KEY file' loop is inside your 'read the DATA file' loop, so KEY only gets read the first time through, then is 'exhausted'. As KEY is small, it'd be easy to read it into an array first.

Forgive the emphasis, but have you seen arrays? Very handy - they save you having to type "$c1,$c2,$c3...". Have a look at how "my @fields = split(/ /)" might help you cut down the amount of 'noise' here, which would help you analyse your poblem a little better.

Cheers
Ben.

  • Comment on Re: How to compare a field in 2 files and set a value if it matches?
  • Download Code

Replies are listed 'Best First'.
Re: Re: How to compare a field in 2 files and set a value if it matches?
by aschroh (Novice) on May 20, 2003 at 22:03 UTC
    Your right let me clarify the problem. When I run the script it runs through it's entirity and the invoicedetail.txt is empty. I set it to print $s1 and $s2 to the screen and I get nothing. I am pretty sure the problem is exactly what benn stated....hadn't thought about that part of it. I do normally use arrays but when things break I take it to down to the simplest manner of expression as possible (even if it does make it look ugly) for the simple reason that when i pull elements from arrays I have a VERY nasty habbit of forgetting they start with 0 not 1....which completely messes me up...still trying to burn that one into my brain. Thanks for your help =).