title: How can I delete duplicate values across arrays stored in hash?
body: <p>I have the following hash:</p>
  
  <pre><code>my %HASH = (
      'List1' =&gt;  [ 'the', 'red', 'cat', 'jumps' ],
      'List2' =&gt;  [ 'the', 'brown', 'fox', 'jumps' ],
      'List3' =&gt;  [ 'a', 'red', 'fox', 'jumps' ],
  );
  </code></pre>
  
  <p>I want to delete duplicate elements across these arrays, so that only unique elements remain. The desired output would be the following:</p>
  
  <pre><code>my %HASH = (
      'List1' =&gt;  [ 'cat' ],
      'List2' =&gt;  [ 'brown' ],
      'List3' =&gt;  [ 'a' ],
  );
  </code></pre>
  
  <p>In other words, if an element is present in both List1 and List2, it should be deleted from both lists.</p>
  
  <p>I have tried to do the following:</p>
  
  <pre><code>use strict;
  use warnings;
  use diagnostics;
  use Data::Dumper;
  
  foreach my $key ( keys %HASH )  {
  
      foreach ( @{$HASH{$key}} )  {
  
          if(exists($HASH{$key})){
              @{$HASH{$key}} = delete($HASH{$key});
          }
      }
  }
  
  print Dumper(\%HASH);
  </code></pre>
  
  <p>Which doesn't seem to do anything, the hash remains the way it was. I'm still pretty new to Perl, so I'm not sure where I went wrong with that. But Perldoc says that calling exists on array values is deprecated anyway, so any solution which uses something other than exists is welcome too!</p>