in reply to Print keys corresponding to duplicate values
use strict; use warnings; use feature 'say'; my %hash = ( 'a' => 1, 'b' => 2, 'c' => '1', 'd' => 3, 'e' => '5'); my (%seen,@dups); while (my($k,$v)=each %hash){ if ( defined $seen{$v}){ push @dups,$k; $seen{$v} and push @dups,$seen{$v}; $seen{$v}=''; next } $seen{$v}=$k } say for sort @dups; __OUTPUT__ a c
This is not an optical illusion, it just looks like one.
|
|---|