Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to add values of hash by reading from different text files

by citromatik (Curate)
on Apr 27, 2009 at 07:09 UTC ( #760290=note: print w/ replies, xml ) Need Help??


in reply to How to add values of hash by reading from different text files

Unless you have a good reason for not doing so, always use strict in your code

There are several errors in your code:

  • While processing file2 and file3, you are using the literals key2 and key3 as hash keys, instead of the variables $key2 and $key3
  • While processing file3 and file3 you are incrementing the values of the hashes $hash{key3}++, don't know why
  • Also, when processing the files you are assigning different values to the same hash key:
    $hash{key2} = $value11 + $value1; $hash{key2} = $value22 + $value2;
    the second statement overrides the first. You should be using different (sub)hashes for each value:$hash{$chrX}{value1} += $value11 ...

citromatik


Comment on Re: How to add values of hash by reading from different text files
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (22)
As of 2015-07-01 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (6 votes), past polls