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


In reply to Ensuring Each If Statement Is Evaluated by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.