On Wed, Jul 9, 2014 at 10:35 PM, Jim Gibson <jimsgib...@gmail.com> wrote:
> > On Jul 9, 2014, at 1:20 PM, Natxo Asenjo wrote: > > > hi, > > > > i have an array of arrays which contains equal elements. I would like to > isolate the unique values. > > Do you mean that the subarrays contain equal NUMBERS of elements? yes, same number of elements but some subarrays are exactly the same as well. like this: $VAR1 = [ [ 'a', 'b', 'c', 'd' ], [ 'a', 'b', 'c', 'd' ], [ 'e', 'f', 'g', 'g' ] ]; [knip] If you want to find out the unique values in any collection, insert those > values as keys in a hash. Since keys in a hash are unique, when you are > done inserting, the keys of the hash will be the unique values from your > collection. > > It doesn't matter what values you insert in the hash to go along with your > keys. You are only interested in the keys. However, one common method would > be to increment the hash value each time you insert a key. That way, when > you are done, you will have a count of the number of times each value > appears in your original collection: > > $hash{$key}++; > > where $key takes on each of the values in your original collection. my %uniq; for my $i ( @$seen_ref ) { $uniq{$i} = (); } print Dumper %uniq; $VAR1 = 'ARRAY(0x1f845f0)'; $VAR2 = undef; $VAR3 = 'ARRAY(0x1e01390)'; $VAR4 = undef; $VAR5 = 'ARRAY(0x1f844d0)'; ...... and if I try looping the hash: while ( my ( $k, $v ) = each %uniq ) { print Dumper $k; } $VAR1 = 'ARRAY(0x27a06f8)'; $VAR1 = 'ARRAY(0x270e5e0)'; $VAR1 = 'ARRAY(0x27a0308)'; $VAR1 = 'ARRAY(0x270e280)'; $VAR1 = 'ARRAY(0x27a0398)'; $VAR1 = 'ARRAY(0x27a05d8)'; .... so I do not know if I am doing this right. Thanks! -- groet, natxo