You don't need to read the MAP file for every line of the input, just read it once

#!/usr/bin/perl use strict; open MAPFile,'<',$ARGV[2] or die "$ARGV[2] : $!"; my %hash = (); # Cost Center, Activity my %hash1 = (); # Account while ( <MAPFile> ) { chomp; my ($CC,$Act,$NEWCC,$NEWAct,$Acct,$NEWAcct) = split(',',$_); $hash{$CC}{$Act}[0] = $NEWCC; $hash{$CC}{$Act}[1] = $NEWAct; $hash1{$Acct} = $NEWAcct; } close MAPFile; open SourceFile, '<', $ARGV[0] or die "$ARGV[0] : $!"; open TargetFile, '>', $ARGV[1] or die "$ARGV[1] : $!"; my $count = 0; my $changed = 0; my $changed1 = 0; while (<SourceFile>) { ++$count; my ($Year,$HSP_rates,$Curr,$Scenario,$Version,$Product, $CostCenter,$Activity,$Entity,$Acct,$BegBal,@mth) = split(',',$_); my ($NewCC,$NewAct,$NewAcct); if ( exists $hash{$CostCenter}{$Activity} ){ $NewCC = $hash{$CostCenter}{$Activity}[0]; $NewAct = $hash{$CostCenter}{$Activity}[1]; print "line $count : updated $CostCenter to $NewCC\n"; ++$changed; } else { $NewCC = $CostCenter; $NewAct = $Activity; } if ( exists $hash1{$Acct} ){ $NewAcct = $hash1{$Acct}; print "line $count : updated $Acct to $NewAcct\n"; ++$changed1; } else { $NewAcct = $Acct; } print TargetFile join ',', $Year,$HSP_rates,$Curr,$Scenario,$Version,$Product, $NewCC,$NewAct,$Entity,$NewAcct,$BegBal,@mth; } print "$count lines processed $changed changes to CostCenter,Activity codes $changed1 changes to Account codes\n"; close SourceFile; close TargetFile;

Update ; %hash1 added for Acct mappings


poj

In reply to Re^14: Mapping & Hash Issues by poj
in thread Mapping & Hash Issues by sandeepsinghperl

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.