CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: How to shrink code by reducing if conditions : Edit Log


Apr 23, 2014, 3:59 AM

Views: 30152
How to shrink code by reducing if conditions

Currently This is the perl script iam actullay using to geberate an output file
I have more than 240 if conditions but not pasted it
But it is really huge code.
Is there any other way to shrink it , Input file is a tab delimited file

while (<$in>) {
our $line = $_;
chomp $line;
our $tagged = $line."\tTBD\n"; // This line is appened to the input and stored in output file

if (/\t282\t442\t/ && (/Pay_CC/ || /ENVIO_/)) {$tagged = $line."\tOTC\tPPLAT\tAutomated\tCredit Card Hppy\t\n";}
if (/\t181\t442\t/ && (/Pay_DD/)) {$tagged = $line."\tOTC\tPPLAT\tAutomated\tDirect Debit Hppy\n";}
if (/\t181\t442\t/ && (/ThirdPartyPoint/)) {$tagged = $line."\tOTC\tPPLAT\tAutomated\tThird Party Points Hppy\n";}
if (/\t181\t442\t/ && (/Pay_Carrier/)) {$tagged = $line."\tOTC\tPPLAT\tAutomated\tMobile Carrier Billing Hppy\n";}
if (/\t181\tRemittance\t/ && (/CHARGEBACK/)) {$tagged = $line."\tOTC\tPPLAT\tAutomated\tCC Chargeback\n";}
if (/\t181\tAdjustment\t/ && (/ADJUSTMENT/)) {$tagged = $line."\tOTC\tPPLAT\tAutomated\tCredit Card Adjustment\n";}
if (/\t1221\t442\t/ && (/Pay_CC/ || /FailureAfterSuccess/)) {$tagged = $line."\tB4KELVIN\tPPLAT\tAutomated\tCredit Card Hppy\n";}
if (/\t1221\t442\t/ && (/Pay_DD/)) {$tagged = $line."\tB4KELVIN\tPPLAT\tAutomated\tDirect Debit Hppy\n";}
if (/\t1221\t442\t/ && (/Disbursement/ && /Failure/)) {$tagged = $line."\tB4KELVIN\tPPLAT\tAutomated\tDisbursement Failure\n";}
if (/\t1221\t442\t/ && (/ECheck/)) {$tagged = $line."\tB4KELVIN\tPPLAT\tAutomated\teCheck Hppy\n";}
if (/\t1221\t442\t/ && (/Invoicing/)) {$tagged = $line."\tB4KELVIN\tPPLAT\tAutomated\tCustomer Invoice Hppy\n";}
if (/\t1221\t442\t/ && (/SVA/)) {$tagged = $line."\tB4KELVIN\tPPLAT\tAutomated\tStored Value Account Hppy\n";}
if (/\t1221\t442\t/ && (/TerminalFailure/)) {$tagged = $line."\tB4KELVIN\tPPLAT\tAutomated\tHppy Terminal Failure\n";}

if (/\t1221\t303\t/ && (/GiveBack/)) {$tagged = $line."\tB4KELVIN\tHEN\tAutomated\tHEN GiveBack Request\n";}

if (/\t1221\t204\t/ && (/ShipmentComplete/)) {$tagged = $line."\tB4KELVIN\tCOW\tAutomated\tProduct Revenue\n";}
if (/\t1221\t204\t/ && (/Shipment_Kelvin/)) {$tagged = $line."\tB4KELVIN\tCOW\tAutomated\tDSV Revenue\n";}

if (/\t1221\t304\t/ && (/Hppy/)) {$tagged = $line."\tB4KELVIN\tGCS\tAutomated\tRGC Redemption\n";}
if (/\t1221\t304\t/ && (/Creation/)) {$tagged = $line."\tB4KELVIN\tGCS\tAutomated\tRGC Issued\n";}
if (/\t1221\t304\t/ && (/GiveBack-for-return/)) {$tagged = $line."\tB4KELVIN\tGCS\tAutomated\tRGC GiveBack-for-Return\n";}
if (/\t1221\t304\t/ && (/GiveBack-to-recipient/)) {$tagged = $line."\tB4KELVIN\tGCS\tAutomated\tRGC GiveBack-to-Recipient\n";}
if (/\t1221\t304\t/ && (/GiveBack-to-purchaser/ && ! /Reversal a/)) {$tagged = $line."\tB4KELVIN\tGCS\tAutomated\tRGC GiveBack-to-Purchaser\n";}
if (/\t1221\t304\t/ && (/GiveBack-to-purchaser/i && /\tReversal a/)) {$tagged = $line."\tB4KELVIN\tGCS\tAutomated\tRGC Reversal of a GiveBack-to-Purchaser\n";}
## SBS (201) ##
if (/\t1221\t201\t/ && (/SuberCharge/)) {$tagged = $line."\tB4KELVIN\tSBS\tAutomated\tSuber Revenue\n";}
if (/\t1221\t201\t/ && (/SuberGiveBack/)) {$tagged = $line."\tB4KELVIN\tSBS\tAutomated\tSuber GiveBack\n";}

(This post was edited by Tejas on Apr 23, 2014, 4:26 AM)

Edit Log:
Post edited by Tejas (User) on Apr 23, 2014, 4:26 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives