in reply to problem with variables in hash values??

In this example, the value of $items{1} is 4 before and after the value of $magic changes.

As it should be. When you initialize %items, you are using the result of calculating $magic*2. This calculation is done once, not automagically each time $magic subsequently changes.

Replies are listed 'Best First'.
Re: Re: problem with variables in hash values??
by poohhogan (Initiate) on Dec 05, 2001 at 04:22 UTC
    Bah! So using a variable there is not useful. Hopefully I'll discover another way to do this when I learn more. Well, at least now I know, so I won't spend hours trying to figure out how to make it work.

    Thanks!!

      Consider a *reference* to a variable:
      $magic=4; #same as 2*2 last time I checked ;-) %items=(1 => \$magic); print "1: ${$items{1}}\n"; $magic+=1; print "1: ${$items{1}}\n";
      See perlref

      --
      perl -p -e "s/(?:\w);([st])/'\$1/mg"