Tuesday, January 4, 2011

Remove Duplicate new method

my @duplicates = (1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 9, 2, 3, 3,);

        my %unique;

        # Our hash here has keys, but all its values will be undefined.
        # That's fine, since we're only interested in the keys.

        @unique{@duplicates} = ();

        my @unique_elements = sort keys %unique;

        print "@unique_elements\n";  # 1 2 3 4 5 6 7 8 9

No comments: