title: How to get key from the reference of a hash element
body: <p>suppose <code>$my_ref = \$hash{'mary'};</code> <code>#my_ref</code> is a reference point to a hash element.<br>
  ....<br>
  later on, how can I use <code>$my_ref</code> to retrieve the key of the hash element it point to? i.e how to get string 'mary' from <code>$my_ref</code>?</p>
  
  <p>I ask this question because I have several groups of user name list, some user names appear in multiple groups which consumes memory. So I decide to create a common user name list, and let these groups only store the reference to the corresponding user name rather than user name.   </p>
  
  <p>e.g. originally,  </p>
  
  <pre><code>%group1 = {'mary'=&gt;1, 'luke'=1,'tom'=1,...}  
  %group2 = {'mary'=&gt;1, 'sam'=1,'tom'=1,...}
  </code></pre>
  
  <p>Here you see 'mary' and 'tom' are shown in both <code>group1</code> and <code>group2</code> which consume memory. (note I do not care the value in this example, the value is here only because the data struct is a hash). So to reduce memory, I want to have a common list stores all user names:   </p>
  
  <pre><code>%common_hash = {'mary'=&gt;1, 'luke'=1,'tom'=1,'sam'=1...};  
  $ref1 = \$common_hash{'mary'};  
  $ref2 = \$common_hash{'luke'};  
  $ref3 = \$common_hash{'tom'};  
  $ref4 = \$common_hash{'sam'};
  </code></pre>
  
  <p>groups only store the reference of the hash element:  </p>
  
  <pre><code>%group1 = {$ref1=&gt;1, $ref2=1,$ref3=1,...};  
  %group2 = {$ref1=&gt;1, $ref4=1,$ref3=1,...}; 
  </code></pre>
  
  <p>I think this approach can save much memory because:</p>
  
  <ol>
  <li>one user name is store in memory once not multiple times;</li>
  <li>groups stores reference (an integer) rather than string (in my case, the length of each user name is 30 bytes in average, while each integer is only 4 bytes (32 bit sys.) or 8 bytes (64 bit sys.)) (BTW, correct me if an integer does not use 4 bytes or 8 bytes.)</li>
  <li>using reference I can access user name immediately without looking for it.</li>
  </ol>
  
  <p>But how can I get the user name from a group?  </p>
  
  <p>If I use <code>@my_ref = keys %group1</code>, I think I will get value of 'mary',but not 'mary'.      </p>
  
  <pre><code>$result = $($my_ref[0]);
  </code></pre>