Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 ...


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2016-10-28 12:59 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.