To the OP - just keep in mind that if this is a Perl homework assignment, your professor is probably trolling the site and will notice if you use this code. Otherwise, have fun with it.
use strict; use warnings; my %HoA = ( flintstones => [qw/fred barney george/], jetsons => [qw/george fred elroy/], simpsons => [qw/fred marge bart barney/] ); my (%dupes, $k1, $k2, $i); ### Count instances of each word. ### I'm assuming, for the sake of argument, that there ### are no duplicates inside each array. for $k1 (keys %HoA) { $dupes{$_}++ for @{$HoA{$k1}}; } ### For each duplicated word for $k2 (sort keys %dupes) { next if $dupes{$k2} < 2; ### Output matches for $k1 (sort keys %HoA) { for ($i = 0; $i <= $#{$HoA{$k1}}; $i++) { print "\$HoA{'$k1'}[$i] = '$k2';\n" if $HoA{$k1}[$i] eq $k2; } } print "\n"; }
In reply to Re: get duplicates in hash array
by TJPride
in thread get duplicates in hash array
by arunshankar.c
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |