Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Adding the duplicate data using arrays

by biohisham (Priest)
on Aug 11, 2010 at 07:49 UTC ( #854261=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2022-12-06 00:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?