Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Answer: How do I find unique Array in Array of Arrays?

by bart (Canon)
on Dec 18, 2007 at 13:23 UTC ( #657671=categorized answer: print w/replies, xml ) Need Help??

Q&A > arrays > How do I find unique Array in Array of Arrays? - Answer contributed by bart

There's a likely cheaper solution to stringify an array of strings (no nested arrays) than using Data::Dumper: if you first quotemeta every string and then join by any \W character (except '\'), then you can uniquely recognize any combination of characters in the arrays, because the join string will not have a prepending backslash, and every \W character in the data will.

In addition, I'm using fewer extra data structures than in the other proposed solutions.

my %seen; my @aoa = grep { not $seen{join " ", map quotemeta, @$_}++ } @AoA;

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-10-21 07:53 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (212 votes). Check out past polls.