title: How can I add only unique values to an anonymous array used as a hash value?
body: <p><strong>EDIT</strong> Sorry I forgot the most important part here. Each key <em>can</em> have more than one value. Apologies to those who already answered. <code>print</code> and <code>join</code> will be used later to print multiple values for <code>$key</code> on a single line.</p>
  
  <p>In the example code below, assuming that the value <code>$keyvalue</code> is constantly changing, I am attempting to use a single line (or something similarly contained) to test and see if the current <code>$keyvalue</code> already exists. If it does, then do nothing. If it does not, then push it. This line would reside within a while statement which is why it needs to be contained within a few lines.</p>
  
  <p>Preserving order does not matter as long as there are no duplicate values.</p>
  
  <pre><code>my $key = "numbers";
  my $keyvalue = 1;
  
  my %hash = ($key =&gt; '1');
  
  push (@{$hash{$key}}, $keyvalue) unless exists $hash{$key};
  </code></pre>
  
  <p>I am not getting any errors with <code>use strict; use warnings;</code>, but at the same time this is not working. In the example above, I would expect that since the default value is <code>1</code> that the <code>$keyvalue</code> would not be pushed as it is also <code>1</code>.  Perhaps I have gotten myself all turned around...</p>
  
  <p>Are there adjustments to get this to work or any alternatives that can be used instead to accomplish the same thing?</p>