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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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



Tejas
User

Apr 24, 2014, 3:09 AM


Views: 30077
Re: [Laurent_R] How to shrink code by reducing if conditions

Hi

Well, I have shortened the code and the input file and attached them.
And the code just handles whtever is there in the input file
Perhaps, this wouldnt confuse.

Is there any other way to it.
As the number of hashes would end up being 270 totallyy

Code is below


Code
 
#! /usr/bin/perl
#181 => TOC
#202=>STALLS
#Just created hash for some combinations, there are many such combitions , but most of them have identical first and second values in hash
my %hash;

$hash{181}{202}{CardRead}="\tTOC\tSTALLS\tAuto\tCard\tID14,15,17,20\n";
$hash{181}{202}{ENVIO_R}="\tTOC\tSTALLS\tAuto\tCard\tID14,15,17,20\n";
$hash{181}{202}{ENVIO_C}="\tTOC\tSTALLS\tAuto\tCard\tID14,15,17,20\n";
$hash{181}{202}{CardWrite}="\TOC\tSTALLS\tAuto\tDCard\n";
$hash{181}{202}{CardTPP}="\tTOC\tSTALLS\tAuto\tTPPS\n"; #Repeated Below
$hash{181}{202}{CardCPP}="\tTOC\tSTALLS\tAuto\tTPPS\n";
$hash{181}{Remittance}{PALLI_CHAT}="\tTOC\tSTALLS\tAuto\tCCA \n";#Repeated Below
$hash{181}{Adjustment}{PP_VP}="\tTOC\tSTALLS\tAuto\tCCA \n";

my $pwd = `pwd `;
chomp ($pwd);

my $INP = "$pwd/Input.txt";
open IN, "< $INP" or die "Could not open input file: $!\n"; ;


my $OUTP = "$pwd/Result.txt";
open OUT, "> $OUTP" or die "Could not open output file: $!\n";;


while(my $line = <IN>)
{
chomp($line);
my ($Source,$Category,$Desc) = (split "\t",$line)[4,5,7];
if($hash{$Source}{$Category}{$Desc}){
print OUT "$line.\t$hash{$Source}{$Category}{$Desc}";
}
}


Thanks
Tejas


(This post was edited by Tejas on Apr 24, 2014, 6:34 AM)
Attachments: Input.txt (238 KB)


Edit Log:
Post edited by Tejas (User) on Apr 24, 2014, 4:00 AM
Post edited by Tejas (User) on Apr 24, 2014, 6:25 AM
Post edited by Tejas (User) on Apr 24, 2014, 6:32 AM
Post edited by Tejas (User) on Apr 24, 2014, 6:34 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