When you declare a variable with my, the declaration takes effect for the following statement. This allows you to do things like:
#!perl my $x = 'outer'; { my $x = $x; # new $x, copy value from old $x print "$x\n"; $x = 'inner'; print "$x\n"; } print "$x\n"; __END__
In your code, you need to declare %HoH before you reference it. For example:
my %HoH; %HoH = ( yadda1 => { key1 => "value1", key2 => &GetValue, # returns date string key3 => &Compare($var1,$HoH{yadda1}{key2}), }, yadda2 => { key1 => "value1", key2 => &GetValue, # returns date string key3 => &Compare($var1,$HoH{yadda2}{key2}), }, );
That will avoid the warning from strict, but it doesn't actually solve the problem. When you assign to a variable, if you refer to that same variable on the RHS of the assignment, you will get the old value of the variable. This is a lot like what happens with my:
my %HoH = ( key1 => 'first' ); %HoH = ( key1 => 'second', key2 => $HoH{key1}, );
$HoH{key2} will be 'first', because that was the value of $HoH{key1} when the RHS of the assignment was evaluated.

I would suggest you do something like this:

my $date_string = &GetValue; my $comparison = &Compare($var1, $date_string); %HoH = ( yadda1 => { key1 => "value1", key2 => $date_string, key3 => $comparison, }, yadda2 => { key1 => "value1", key2 => $date_string key3 => $comparison, }, );

In reply to Re: Re-using a hash value in same hash? by chipmunk
in thread Re-using a hash value in same hash? by oakley

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.