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

The big problem here is that you try to read KEY over and over, once for each line of DATA. It will read the KEY file once for the first line of DATA and then fail. Instead, you should store the values from KEY in a hash first:
my %keyval = (); while(<KEY>){ ($s1,$s2) = split(/,/); $keyval{$s1} = $s2; }
In the DATA loop, look up $c5 in the hash:
if (exists $keyval{$c5}) { $custnmbr = $keyval{$c5}; $flag = 1; }
Also, you might want to split into an array instead of using such repetitive variable names.

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 23:34 UTC
    Your solution worked like a charm. I appreciate your assistance =)......I do normally use @c to split things out but when I get into trouble I break things down to their simplest form (and easiest way of understanding them) to sort them out. Mainly cause I always forget that and array starts at 0 not 1 and always figure I fubared myself by skewing everything by forgetting to start at 0.... aschroh
Re: Re: How to compare a field in 2 files and set a value if it matches?
by Anonymous Monk on Jul 17, 2003 at 09:25 UTC
    should this also work for strings...I have tried this on data(numbers) and it works ok but on a string it does not work