Hi All looking for help with a script that looks to a csv file to dete +rmine how to parse another file in order to get an end value. Table: #PTC,FTC,QUAN,QSIGN,AMT,ASIGN,ST ADM,RCV,,+,,, ADM,DLV,,,,, ABC,EFG,,,,,8 ABC,XYZ,,-,,,7 for the first example: if field1 ne "" field4 ne "" then I want to build a statement using the 3 fields that are populated +: if ($CODE1 eq "$field1") && ($CODE4 eq "$field4) { $TRN = "$field2"; } if field1 ne "" field7 ne "" if ($CODE1 eq "$field1") && ($CODE7 eq "$field7) { $TRN = "$field2"; } if field1 ne "" if ($CODE1 eq "$field1") { $TRN = "$field2"; } The $CODE* fields are fields I have already parsed from a line in a te +xt file and then if there is a match assign $TRN. Trying to avoid having to right 100s of if statements for each possibl +e scenario. &GetTrnCode($X); sub GetTrnCode ($) { $CODE = ""; $TRANCODE = ""; $PERcode=""; $FDXcode=""; $CODE = $_[0]; my %TrnCode; $data2 = "PerTrnTable.txt"; open(inData2, $data2); while (<inData2>) { chomp; $line2 = $_; my $PERcode = (split(/,/,$line2))[0]; my $FDXcode = (split(/,/,$line2))[1]; my $QUANTITY1 = (split(/,/,$line2))[2]; my $QSIGN1 = (split(/,/,$line2))[3]; my $AMT1 = (split(/,/,$line2))[4]; my $ASIGN = (split(/,/,$line2))[5]; my $SECTYPE1 = (split(/,/,$line2))[6]; if (($CODE eq $PERcode) && ($QSIGN eq $QSIGN1) && ($AMTSIG eq $ASIG +N) && ($SECTYPE eq $SECTYPE1)){ $TRNCODE = $FDXcode; } } } close inData2; } This is where I am at, but In many it does not matter what each field +is so I do not want to compare fields if in the table the field is bl +ank. in this example it would return TRN = RCV and DLV, which is not what I + want to do. I would want to return TRN = DLV because the other field +s in the table are blank if ($CODE1 eq "$field1") { $TRN = "$field2"; } Thanks in advace,
In reply to Building If Statements by mmittiga17
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |