OK, I won't actualy recomend this, as its higly magical, and it is not very intuitve what you are doing.(Id hate to maintain code like this....)

I'll also call you globalHash globalHash if you dont mind. You'll understand why...

Anyway, the globalHash is stored in something called a glob. Now a glob is sort of a hash, with the values beeing references to everything that can be called globalHash. So the %globalHash is actually stored as a reference to a hash in the *globalHash glob. (There is also a refernce to a list, in case you define @globalHash. Since you probably haven't that refernce is probably undef in your program) Now, to set %globalHash to a new hash, simply set the glob to an empty hash reference like this:

push %AoH, \%globalHash; *globalHash={};
That sets the hash part of the glob to a new, empty hash reference, so that %globalHash is now empty. The good thing is that a glob works a lot like a hash table, so the old hash you had stored there is not gone. There are still references to it in your AoH list. Its just not possible to get at it through the globalHash anymore. Magic, huh...

Anyway, by assigning a scalar reference(number, string etc) to the *globalHash glob, you will change the scalar part in the glob. Assigning a list reference will change the list part of it. Note also that this won't work for variables you have declared with my as those don't use glob's.

goldclaw


In reply to Re: O, the horrors of references and complex data structures by goldclaw
in thread O, the horrors of references and complex data structures by DeusVult

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.