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

First, your question is well written. That is one reason you got such a quick response from CountZero.

I am frankly surprised that you have not been taught about my yet. Best practice in Perl programming expects you to use strictures and my/our. Given that this advice is in all of the well known recent Perl training books, your professor is likely to assume that you simply did your homework. If you are concerned, look up a citation and include in in an explanatory note in your code. You can find an appropriate citation in the Camel book or any of the books listed here. "Here" is the Perl page of Larry Wall, the inventor of Perl. You can also probably find a citation even your own textbook. Surely you are allowed to read ahead in your own textbooks?

my declares variables. Strictures are the two lines at the top of CountZero's script: use strict; use warnings; Among other things strictures require you to declare variables (with either my or our) and warn you when you are using variables in ways that you probably shouldn't. Unless you have a very specific (and expert) reason, you should always use these two lines at the top of every script.

Now for how to fix your own code. Your code isn't working because you and your group mate need to use and understand the concepts of Autovivification and Hashes of Hashes. Specifically, relating to your script:

Best, beth

Replies are listed 'Best First'.
Re^2: How to add values of hash by reading from different text files
by faozhi (Acolyte) on Apr 27, 2009 at 07:34 UTC
    Hi Beth,

    Firstly, thank you so much for your really helpful reply.
    I am using O'REILLY Learning Perl as my guide and reference book. However, hash of hashses and autovivification isn't in the book, which was why I got stuck
    And honestly, i am not an IT student and I am self learning perl. I need to use this for some of my research work related to genetics.

    Cheers
      A very good (and free) book to (self) learn Perk is "Beginning Perl" which can be found here. "use strict; and the use of my are explained in Chapter two, page 66.

      I use this book in the Perl programming course I teach in our local computer club.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James