It would help if you post a bit of code so we can see what's going on. You are correct that a hash declared globally should retain its data throughout the program, but there are various ways one could subvert this. Perhaps you have redefined the hash within subs? Maybe you're not really assigning to the hash keys? Are you using conditionals that fail without warning? Is your hash being populated through files that aren't being opened, but you don't know that because you didn't check for a successful open? The possibilities are endless.

First, make sure that you are using the -w switch at the beginning of your program, that might catch a few things. Also, use strict;.

The only sure advice I can give you is to learn to use the perl debugger. Then, if your hash is named %somehash, when you get to an area of the program where the hash should be populated, you can type x %somehash to have a nicely formatted print of the hash contents, if any.

If you do post some code, be sure to wrap the code in <CODE></CODE> tags so it will be properly formatted.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just go the the link and check out our stats.


In reply to (Ovid) Re: make a hash globally accessible by Ovid
in thread make a hash globally accessible by vipinh

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.