Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Mapping & Hash Issues

by sandeepsinghperl (Novice)
on Mar 29, 2017 at 17:12 UTC ( #1186399=note: print w/replies, xml ) Need Help??


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

Hi, I am very new to perl and struggling. Is it possible please if you can give me the code as per the requirement. Somehow <code> is not working for me sure i am doing something wrong. Thanks

Replies are listed 'Best First'.
Re^3: Mapping & Hash Issues
by Anonymous Monk on Mar 29, 2017 at 17:14 UTC
    use strict; use warnings; use Text::CSV; die "usage: $0 SourceFile TargetFile MappingFile\n" if @ARGV < 3; my $csv = Text::CSV->new({ auto_diag=>1, binary=>1, eol=>"\n" }); my %map; open my $MAP, '<', $ARGV[2] or die "Can't read $ARGV[2]: $!"; while (my $row = $csv->getline($MAP)) { my ($old_cost, $old_act, $new_cost, $new_act) = @$row; $map{$old_cost}{$old_act} = [$new_cost, $new_act]; } close $MAP; open my $IN, '<', $ARGV[0] or die "Can't read $ARGV[0]: $!"; open my $OUT, '>', $ARGV[1] or die "Can't write $ARGV[1]: $!"; while (my $row = $csv->getline($IN)) { if (my $new = $map{$row->[6]}{$row->[7]}) { $row->[6] = $new->[0]; $row->[7] = $new->[1]; } $csv->print($OUT, $row); } close $IN; close $OUT;
      Re: Give a man a fish...
      Sometimes, you have to show him what a fish looks like first.

      First , thanks for being patient and youyr help. i ran the code its giving the below Error and nothing is coming up in the Target file.

      =========================================================================================

      C:\Users\sksingh>perl "C:\Users\sksingh\Documents\Barrick Work\Perl\GC +OA\newway.pl" "C:\Users\sksingh\Documents\Barrick Work\Perl\GCOA\NAAC +T.txt" "C:\Users\sksingh\Documents\Barrick Work\Perl\GCOA\NAACTDEPEND +.txt" "C:\Users\sksingh\Documents\Barrick Work\Perl\GCOA\FINALMAPDEPE +NDENT.txt" # CSV_XS ERROR: 2023 - EIQ - QUO character not allowed @ rec 1840 pos +12 field 1

      =========================================================================================

        First, <code> tags are easy to use. When you're entering your post, type something like this:
        <code>
        for my $i (1 .. 10) { print "And a $_,\n"; }
        </code>

        And it will come out looking nice. If you leave off the <code> and </code>, it will be all jumbled together and people will yell at you. Also, instead of typing a row of equal signs like you've been doing, you can instead use <hr>, which stands for horizontal rule.

        Second, as runrig says, there's probably something weird in your input file. Try looking at line 1840. Try making a smaller input file to make testing easier.

        Maybe there's something wrong with record 1840 in your input file?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1186399]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2023-02-04 03:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (30 votes). Check out past polls.

    Notices?