in reply to Adding the duplicate data using arrays

Just as Rata mentioned, a hash is more logical a solution in this case, a very simple hash approach can perform the job quite efficiently...

how do i compare the array data?...
Using a hash you don't have to compare data because all you need is just a hash key to hold all the data that belong to that type of fruit...

Consider
use strict; use warnings; use Data::Dumper; my %hash; while(<DATA>){ my ($key, $number)=split; $hash{$key} +=$number; } print Dumper (\%hash); __DATA__ apples 10 oranges 3 apples 3 oranges 7


Excellence is an Endeavor of Persistence. A Year-Old Monk :D .

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.