Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 perusing the Monastery: (15)
As of 2014-07-30 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls