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


In reply to Re: How to add values of hash by reading from different text files by ELISHEVA
in thread How to add values of hash by reading from different text files by faozhi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.