in reply to Comaring contents of 2 Hash of Arrays

If I understand what you are asking correctly, all you should need to do is :
my %Non_Matches; foreach (keys(%HoL_compare_pub)) { if (!(defined($HoL_pub{$_}))) { $Non_Matches{$_} = $HoL_compare_pub{$_}; } }
The Non_Matched hash will contain only the value key pairs where HoL_compare_pub exists and HoL_pub doesn't. Hope this helps. Dave </code>

Replies are listed 'Best First'.
(bbfu) (hash elements are array refs)Re: Re: Comaring contents of 2 Hash of Arrays
by bbfu (Curate) on Feb 20, 2001 at 09:37 UTC

    No, I think that s/he means that s/he wants to compare each of the values in the arrays pointed to (via array refs) by the corresponding keys in each hash. What I can't tell is if s/he expects the items to be in the same order in each hash or not.

    If so, the most straight-forward way to do it would be something like:

    my @Non_Matching_Keys; foreach $key (keys %HoL_compare_pub) { my @orig_a = @{$HoL_pub{$key)}; my @comp_a = @{%HoL_compare_pub{$key}}; foreach(0 .. @orig_a) { if($orig_a[$_] ne $comp_a[$_]) { push @Non_Matching_Keys, $key; } } }

    Note that that is totaly untested. Also, if the order of the two arrays are different, it won't work. Maybe running a sort() on them both first would work?

    Update: Nevermind... I think I got confused by the "Hash of Arrays" part (and I was in a hurry to leave work ;-)... Looks like Tuna just wanted to see if a router (hash element) existed in one hash and not the other, just like dfog and dkubb said. =)

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.