What I need to do is to export a CSV file (see "FILE2 Example") and change the price of that part e.g. "2.64" to "3.28.
I have a list of 4000 parts that need to be compared with a file that might have 20K+ lines (New prices for parts).
What I was trying to do is create a "Hash" of FILE1 consisting of the part number and its corresponding price.
Then in FILE2 search using the part number and aligning the part number in the hash to return the new price.
Put the price back into the 'string' and write all of that to a new file.
My main Question would be how can I do this HASH compare?
Or How to I execute a 'sub' inside the second while statement.
FILE1 Example
AYP :104757X421 : 3.28 "HUB CAP AXLE"
FILE2 Example
,Active,Inventory Part,AYP-A2:104757X421,HUB CAP AXLE,Tax,4050 · Sales,5000 · Cost of Goods Sold,1300 · Inventory:1310 · Parts,0.00,HUB CAP AXLE,1.00,0.99,,,2.64,
FILE 2 Example is one line of data with that consists of 17 positions in an array.
"CODE START"
use strict;
open (FILE1, "C:\\CNTWork\\items1.csv") or die "Sorry!";
open (FILE2, "C:\\CNTWork\\output1.txt") or die "Sorry Wont open!";
while (<FILE2>) #OPEN THE FILE TO GET A PART NUMBER => PRICE.
{
my $line = $_;
my @a = split(/ /,$line);
my %hash;
%hash = $a[1]." ". $a[2]. "\n";
}
close (FILE2); #THIS SHOULD CREATE A HASH CONSISTING OF A PART NUMBER and its cooresponding price
while (<FILE1>) #THis file will open the CSV file replace the cost @array[13] with the value found in %hash.
{
my @array = split(/,/,<FILE1>);
#my $str1 = $array[15];
#print $array[3]. " ";
#print $array[15] . "\n";
print $array[0] .",". $array[1].",". $array[2].",".$array[3].",". $array[4].",". $array[5].",".$array[6].",".$array[7].",".$array[8].",".$array[9].",".$array[10].",".$array[11].",".$array[12].",".$array[13].",".$array[14].",".$array[15].",".$array[16].",".$array[17];
print $array[3]."\n";
print $hash ; #ERROR HERE, I wanted to see if the hash has a value
}
close (FILE1)
**** CODE END ****
The second "while" is looping though a file that has parts and prices (to make a long story short) the purpose of the hash is to have a reference of the part number to a new price.
I am really new to this. I have been tryhing to think thorough ways of doing this, but I keep coming up short.
I have a list of 4000 parts that need to be compared with a file that might have 20K+ lines (New prices for parts).
What I was trying to do is create a "Hash" of FILE1 consisting of the part number and its corresponding price.
Then in FILE2 search using the part number and aligning the part number in the hash to return the new price.
Put the price back into the 'string' and write all of that to a new file.
My main Question would be how can I do this HASH compare?
Or How to I execute a 'sub' inside the second while statement.
FILE1 Example
AYP :104757X421 : 3.28 "HUB CAP AXLE"
FILE2 Example
,Active,Inventory Part,AYP-A2:104757X421,HUB CAP AXLE,Tax,4050 · Sales,5000 · Cost of Goods Sold,1300 · Inventory:1310 · Parts,0.00,HUB CAP AXLE,1.00,0.99,,,2.64,
FILE 2 Example is one line of data with that consists of 17 positions in an array.
"CODE START"
use strict;
open (FILE1, "C:\\CNTWork\\items1.csv") or die "Sorry!";
open (FILE2, "C:\\CNTWork\\output1.txt") or die "Sorry Wont open!";
while (<FILE2>) #OPEN THE FILE TO GET A PART NUMBER => PRICE.
{
my $line = $_;
my @a = split(/ /,$line);
my %hash;
%hash = $a[1]." ". $a[2]. "\n";
}
close (FILE2); #THIS SHOULD CREATE A HASH CONSISTING OF A PART NUMBER and its cooresponding price
while (<FILE1>) #THis file will open the CSV file replace the cost @array[13] with the value found in %hash.
{
my @array = split(/,/,<FILE1>);
#my $str1 = $array[15];
#print $array[3]. " ";
#print $array[15] . "\n";
print $array[0] .",". $array[1].",". $array[2].",".$array[3].",". $array[4].",". $array[5].",".$array[6].",".$array[7].",".$array[8].",".$array[9].",".$array[10].",".$array[11].",".$array[12].",".$array[13].",".$array[14].",".$array[15].",".$array[16].",".$array[17];
print $array[3]."\n";
print $hash ; #ERROR HERE, I wanted to see if the hash has a value
}
close (FILE1)
**** CODE END ****
The second "while" is looping though a file that has parts and prices (to make a long story short) the purpose of the hash is to have a reference of the part number to a new price.
I am really new to this. I have been tryhing to think thorough ways of doing this, but I keep coming up short.