Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Fast Way to Return Unique Array of Array

by pg (Canon)
on Sep 05, 2005 at 07:16 UTC ( [id://489160]=note: print w/replies, xml ) Need Help??


in reply to Fast Way to Return Unique Array of Array

Slightly modify the original uniq(), it works:

use Data::Dumper; my @AoA = (['a','b','c'], ['a','b','c'], ['a','b','d'], ['a','b','d']); my @uAoA = uniq(@AoA); print Dumper \@uAoA; sub uniq () { my %h; map { $h{join($;, @$_)}++ == 0 ? $_ : () } @_; }

Replies are listed 'Best First'.
Re^2: Fast Way to Return Unique Array of Array
by calin (Deacon) on Sep 05, 2005 at 10:17 UTC

    Nice, just a slight style improvement:

    map { $h{join($;, @$_)}++ == 0 ? $_ : () } @_;

    becomes

    grep { ! $h{join($;, @$_)}++ } @_;
      Could one replace join($;, @$_) with Dumper($_) (or some variant thereof), to allow for multiple levels of data structure?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-23 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found