First off, thank you to everyone who stepped up to help me with this question. So I followed the advice that was given and wrote a little test script which went something like this:
my @array; my %hash; &callaFunction(); &callaFunction(); &callaFunction(); foreach my $element ( @array ) { my %localHash = %{$element}; # print %localHash's contents } sub callaFunction { # fill %hash with random info push ( @array, {%hash} ); }
And this script worked perfectly well. Each index of the array was unique (as opposed to if I made calls to push @array, %hash; in which case every index of the array contained a reference to the same hash, with whatever values were put in the hash last).

However, when, armed with this newfound knowledge, I sallied forth into my main program and applied what I had learned, I was thoroughly vexed to find that my original problem had once again reared its ugly head! That is to say, although I called

push ( @globalArray, {%globalHash} );
I found that each element of @globalArray had the same values within it. So somehow, although I created anonymous hashes to push onto the array, a single reference to the same hash was pushed onto the array again and again.

Monks, I am at a loss. The inner magics of references are but newly known to me. So my question to you, O monks whose wisdom shines like a stream of bat urine on a moonlit night, is this: how could the call to push which I describe above still result in the same reference being pushed onto my array repeatedly?

Some people drink from the fountain of knowledge, others just gargle.


In reply to Night of the Day of the Dawn of the Son of the Bride of the Return of the Attack of the Revenge of 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.