batrams has asked for the wisdom of the Perl Monks concerning the following question:
File A Field 0: Part Number Field 1: Description Field 2: Price
File B Field 0: Part Number Field 1: Description Field 2: New Part Number Field 3: Price
I read File A's data in using this code. I'm sure it can be done in other or more efficient ways but this works well for me:I then read File B's data in a similar way:################################# # reading data in from File A while ( <> ) { $csv->parse($_); push(@AoA, [$csv->fields]); } # load up the hash for my $i ( 0 .. $#AoA ) { $HoA{$AoA[$i][5]} = $AoA[$i]; } # end looping over rows #################################
Now I want to append data from File B onto the the hash I made from File A. If the file structures were identical I could simply do this:################################# # reading data in from File B while ( <TEXTFILE> ) { $csv->parse($_); push(@H_USES, [$csv->fields]); } close(TEXTFILE); print "Done Loading USES Data\n"; # load up the hash for my $i ( 0 .. $#H_USES ) { $H_USES{$H_USES[$i][5]} = $H_USES[$i]; } # end looping over rows #################################
But of course they are not identical. I want to simply ignore or skip over Field 2 from File B. I'm having trouble cooking up how to do this, so I thought I'd ask the gurus here. Any ideas would be appreciated.################################## # Add on File B's data for my $i ( 0 .. $#H_USES ) { $HoA{$H_USES[$i][5]} = $H_USES[$i]; } # end looping over rows ##################################
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Add part of one hash to another
by kennethk (Abbot) on Feb 26, 2013 at 15:23 UTC | |
|
Re: Add part of one hash to another
by mbethke (Hermit) on Feb 26, 2013 at 15:25 UTC | |
by batrams (Novice) on Feb 26, 2013 at 16:04 UTC | |
by tangent (Parson) on Feb 26, 2013 at 16:28 UTC | |
|
Re: Add part of one hash to another
by nvivek (Vicar) on Feb 27, 2013 at 05:49 UTC |