http://qs321.pair.com?node_id=1186431


in reply to Re^7: Mapping & Hash Issues
in thread Mapping & Hash Issues

Hi Again

My input file have

"BegBalance" "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oc +t" "Nov" "Dec" "Period" ,,,,,,,,,,,,,,,,,, "FY01","HSP_InputValue","Local","Plan","Final","10","C4000","A0000","E +1900","52112",#Mi,1,2,3,4,5,6,7,8,9,10,11,12 "FY01","HSP_InputValue","Local","Plan","Final","10","C4000","A0000","E +1900","52122",#Mi,1,2,3,4,5,6,7,8,9,10,11,12

My Mapping file have

"C4000","A0000","C4910","A5854"

My output file is getting generated after running your script is below, Ideally it should check "C4000","A0000" in mapping file if its there then has to update both with "C4910","A5854" for all the rows/line. What your script is doing its just updating the first Row and from second its just updating C4000 to C4910 but not updating A0000 to A5854. I dont have A4910 and A0000 combination in mapping file.

If you are ok then can i send you a webex please so that you can take look ?

"BegBalance" "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oc +t" "Nov" "Dec" "Period" ,,,,,,,,,,,,,,,,,, "FY01","HSP_InputValue","Local","Plan","Final","10","C4910","A5854","E +1900","52112",#Mi,1,2,3,4,5,6,7,8,9,10,11,12 "FY01","HSP_InputValue","Local","Plan","Final","10","C4910","A0000","E +1900","52122",#Mi,1,2,3,4,5,6,7,8,9,10,11,12

Replies are listed 'Best First'.
Re^9: Mapping & Hash Issues
by poj (Abbot) on Mar 29, 2017 at 20:10 UTC

    Post the code you are using to get that output from that input

    poj
      use warnings; open (SourceFile, "$ARGV[0]"); open (TargetFile, ">$ARGV[1]"); while (<SourceFile>) { # Remove the last character from the line. #$Line = substr($_,0,-1); chomp; ($Year,$HSP_rates,$Curr,$Scenario,$Version,$Product,$CostCenter,$Activ +ity,$Entity,$Acct,$BegBal,$Jan,$Feb,$Mar,$Apr,$May,$Jun,$Jul,$Aug,$Se +p,$Oct,$Nov,$Dec) = split(',',$_); print TargetFile "$Year,"; print TargetFile "$HSP_rates,"; print TargetFile "$Curr,"; print TargetFile "$Scenario,"; print TargetFile "$Version,"; print TargetFile "$Product,"; if( length( $CostCenter ) > 0 ) { open (MAPFile,"$ARGV[2]"); while ( <MAPFile> ) { chomp; my @line = split(',', $_); $hash{$line[0]} = $line[0]; $hash1{$line[0]} = $line[2]; $hash2{$line[1]} = $line[1]; $hash3{$line[1]} = $line[3]; if( $hash{"$CostCenter"} eq "$CostCenter" and $hash2{"$A +ctivity"} eq "$Activity") { $c1 = $hash1{"$CostCenter"} and $a1 = $hash3{" +$Activity"}; goto ed; } else { $c1 = "$CostCenter"; $a1 = + "$$Activity"; + } } ed: close(MAPFile); print TargetFile "$c1,"; print TargetFile "$a1,"; print TargetFile "$Entity,"; } if( length( $Acct ) > 0 ) { open (MAPFile,"$ARGV[2]"); while ( <MAPFile> ) { chomp; my @line = split(","); $hash{$line[4]} = $line[4]; $hash1{$line[4]} = $line[5]; $hash2{$line[4]} = $line[5]; if( $hash{"$Acct"} eq "$Acct" ) { $b1 = $hash1{"$Acct"}; goto ed; } else { $b1 = "$Acct"; } } ed: close(MAPFile); print TargetFile "$b1,"; } print TargetFile "$BegBal,"; print TargetFile "$Jan,"; print TargetFile "$Feb,"; print TargetFile "$Mar,"; print TargetFile "$Apr,"; print TargetFile "$May,"; print TargetFile "$Jun,"; print TargetFile "$Jul,"; print TargetFile "$Aug,"; print TargetFile "$Sep,"; print TargetFile "$Oct,"; print TargetFile "$Nov,"; print TargetFile "$Dec"; print TargetFile "\n"; } close (SourceFile); close (TargetFile);

        Have you tried the code posted here ?

        poj