Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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]
usemodperl enters an empty gate

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-06-23 19:02 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.