in reply to finding duplicates in an array

Hey. I have a question really similar to this one:
Let's say I have an array with:

(1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (2, 3) (2, 3) (4, 1) (5, 1)

If I wanted to get rid of duplicates of (x, y) AND get rid of any duplicates of the reverse (y, x), how would I best do this?
ie, I want to end up with:

(1, 1) (1, 2) (1, 3) (1, 4) or (4, 1) (1, 5) or (5, 1) (2, 3)

Really appreciate any suggestions! Thanks!

Replies are listed 'Best First'.
Re^2: finding duplicates in an array
by bobf (Monsignor) on Feb 05, 2008 at 03:10 UTC

    If the order of the elements in each (x, y) pair really doesn't matter, then sorting them should result in data that can then be processed using the techniques in finding duplicates in an array. In other words, make both (1, 4) and (4, 1) into the same pair.

    Was that enough of a hint, or do you need an example?

    Update: I couldn't resist.

    my @aoa = ( [1,4], [4,1] ); my @sorted = map { [ sort { $a <=> $b } @$_ ] } @aoa;