perl scipting over multple lines

July 15, 2012 at 08:45:31
Specs: Windows 7
I have a file called listofvalues.txt.the file has over 1000 lines and 5 cloumns
1,232,3434,54343,434343
1,232,100,4546,3456
1,122,45454,4546,3456
2,212,334,5555,4654
...
...
i want to add up the values of the third column if column 1 and 2 are equal and print the result into a file like as follows
1,232,3534,54343,434343
1,122,45454,4546,3456
2,212,334,5555,4654
....
.........
.........
......
how do you think Ican do it in Perl. Since I am new to Perl I am finidng it hard to do this.

See More: perl scipting over multple lines

Report •

#1
July 15, 2012 at 09:04:22
What have you tried thus far?

What warnings/errors are you receiving?


Report •

#2
July 15, 2012 at 09:08:54
To get you started, you'll want to use a hash where the key is the first 2 fields and the value is an array of all of the fields. As you loop over the lines, you check for the existence of the hash key and if found increment the 3rd field as needed. When done, sort and print out the hash.

Report •
Related Solutions


Ask Question