Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Adding the duplicate data using arrays

by biohisham (Priest)
on Aug 11, 2010 at 07:49 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found