http://qs321.pair.com?node_id=1099731


in reply to Comparing 2 hash tables where values are stored in arrays

I think you basically want to compare two arrays which you get by de-referencing values for each key:

#!/usr/bin/perl use strict; use warnings; my %hash1 = ( abc => [ 1, 2, 3, 4 ], cde => [ 4, 5, 6 ] ); my %hash2 = ( abc => [ 1, 3 ], cde => [ 4, 5 ] ); my @hash1only; for my $key ( keys %hash1 ) { my @array1 = @{ $hash1{$key} }; my @array2 = @{ $hash2{$key} }; # build lookup table my %seen; foreach my $element (@array2) { $seen{$element} = 1 } # find only elements in @array1 and not in @array2 foreach my $element (@array1) { unless ( $seen{$element} ) { push @hash1only, $element; } } } @hash1only = sort @hash1only; print "Elements in \%hash1 and not in \%hash2: @hash1only\n";
See recipe 4.8 in Perl Cookbook for more.

And like that ... he's gone. -- Verbal