in reply to Removing duplicate values for a hash of arrays

In this:

my %hash = ( a => [ '1','2', ], b => [ '2','3', ], c => [ '1','2', ], );
are a and c pointing to the same array ref or are they two different arrays just happening to have the same content? This might change the best strategy to remove the duplicates.

Generally, the best way to remove duplicates is to use a hash. So in this case you have to construct the reverse hash to identify the keys of the original hash that you want to keep. And the best way to do this will depend on the anwer to my first question above.

Replies are listed 'Best First'.
Re^2: Removing duplicate values for a hash of arrays
by Eily (Monsignor) on Nov 21, 2013 at 18:30 UTC

    my %hash = ( a => [ '1','2', ], b => [ '2','3', ], c => [ '1','2', ], ); say "$_ => $hash{$_}" for keys %hash;
    c => ARRAY(0x1abd8f0) a => ARRAY(0x1a9f998) b => ARRAY(0x1abd7a0)
    So the two arrays are two different arrays, and you can't compare them with a simple cmp.

      Yes, if the hash is built this way, these will be different array refs, but we don't know how the hash was originally constructed. This is why I asked the question.