Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I currently have a script that reads the contents of an excel file into a hash, keyed on column titles. Each record (approx 20 column titles and one respective value for each) is then looped over and printed to a new file.
The problem I am having is before I print each record to the new file, I want to execute a series of if statements over the record, so that if it matches *any* of the statements, the function is executed accordingly. Here is a code snippet:
my $rec = $G::result[0]; $fh->print( join( "\t", sort keys %$rec), "\n" ); foreach my $rec ( @G::result ) { LogGeneral("Here's the record : $rec"); #B/L = B & f/r p type = RR if (($rec->{"borrow_lend_indicator"} == "B") && ($rec->{"f +ee_rebate_payable_type"} == "RR")) { $rec->{"accrued_fee_rebate_value"} = "+" . $rec->{"acc +rued_fee_rebate_value"}; #B/L = L & f/r p type = RR } elsif (($rec->{"borrow_lend_indicator"} == "L") && ($rec +->{"fee_rebate_payable_type"} == "RR")) { $rec->{"accrued_fee_rebate_value"} = "-" . $rec->{"acc +rued_fee_rebate_value"}; #f/r type = FR } elsif ($rec->{"fee_rebate_payable_type"} == "FP") { $rec->{"accrued_fee_rebate_value"} = "-" . $rec->{"acc +rued_fee_rebate_value"}; #f/r type = FP } elsif ($rec->{"fee_rebate_payable_type"} == "FR") { $rec->{"accrued_fee_rebate_value"} = "+" . $rec->{"acc +rued_fee_rebate_value"}; #B/L = B } elsif ($rec->{"borrow_lend_indicator"} == "B") { $rec->{"actual_cost_of_funds"} = "-" . $rec->{"actual_ +cost_of_funds"}; #B/L = L } elsif ($rec->{"borrow_lend_indicator"} == "L") { $rec->{"actual_cost_of_funds"} = "+" . $rec->{"actual_ +cost_of_funds"}; } foreach my $field ( sort keys %$rec ) { LogGeneral("Here's the field : $rec->{$field}"); $fh->print($rec->{$field},"\t"); } $fh->print("\n"); } $fh->close();
The problem is, it never really checks the record against every single if statement. I can't work out how to fix this. Any pointers / advice is most welcome.
Thanks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Ensuring Each If Statement Is Evaluated
by ignatz (Vicar) on Oct 17, 2002 at 08:31 UTC | |
Re: Ensuring Each If Statement Is Evaluated
by BrowserUk (Patriarch) on Oct 17, 2002 at 08:32 UTC | |
Re: Ensuring Each If Statement Is Evaluated
by azatoth (Curate) on Oct 17, 2002 at 09:13 UTC | |
Re: Ensuring Each If Statement Is Evaluated
by Anonymous Monk on Oct 17, 2002 at 09:04 UTC |