in reply to Re^6: Is there better way to delete dups in an AoH?
in thread Is there better way to delete dups in an AoH?

Yes, it does call for a modified approach. What you want is a way to find each unique combination of two words, but hash keys have to be simple scalars. To uniquify a combination of two strings, we'll need a two-level hash. This relies on the fact that you know the keys of your hash (which makes it effectively a simple array).
my %uniq; for (@$AoH) { $uniq{$_->{page}}{$_->{chap}} = 1; } @$AoH = map { my $k = $_; map { {page => $k , chap=>$_} } keys %{$uniq{$k}}; } keys %uniq;
The principle is the same as before: make a hash entry for each item, then find all the unique keys and rebuild the original AoH from that. The only difference is that we're going two levels deep.

The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re^8: Is there better way to delete dups in an AoH?
by bradcathey (Prior) on Jun 08, 2004 at 11:03 UTC
    Magical! Roy Johnson, thanks for your excellent solution. Honestly, I'm not sure how it works, but I promise to study it."

    —Brad
    "A little yeast leavens the whole dough."