Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Eliminate Array of array duplication

by Utilitarian (Vicar)
on May 19, 2011 at 08:32 UTC ( [id://905631]=note: print w/replies, xml ) Need Help??


in reply to Re: Eliminate Array of array duplication
in thread Eliminate Array of array duplication

I would agree with ikegami's post above, the only thing I'd add it that you should probably sort the array before using it as a key, if [1, 2, 3] , [3, 2, 1] and [2, 1, 3] are considered identical.
my %seen; @AoD = grep !$seen{ join(',', (sort {$a<=>$b} @$_ )) }++, @AoD;
print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Replies are listed 'Best First'.
Re^3: Eliminate Array of array duplication
by ikegami (Patriarch) on May 19, 2011 at 10:02 UTC

    Indeed. If one desires for [1,2,3] and [3,2,1] to be considered identical, they must have identical signatures, and that can be achieved by sorting the numbers.

    I doubt that's going to be a common desire, but if it happens, it's probably cleaner to normalise the data before finding the dups.

    # Normalise the data. @$_ = sort { $a <=> $b } @$_ for @AoD; # Filter out duplicates. my %seen; @AoD = grep !$seen{ join(',', @$_) }++, @AoD;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://905631]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-25 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found