On Jul 9, 2014, at 2:58 PM, Natxo Asenjo wrote: > > > > 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' > ] > ];
So is that 7 unique values (a,b,c,d,e,f,g) or 2 unique values ( (a,b,c,d), (e,f,g,g) )? > my %uniq; > > for my $i ( @$seen_ref ) { > $uniq{$i} = (); > } If $seen_ref is a reference to an array of arrays, then the elements of @$seen_ref are references to arrays. By using those as keys, you are comparing references and not list elements. In order to use the hash method of determining uniqueness, you must convert your list values to a scalar value based on the content of the lists, not the location or identity of the lists as by using the references to the list. The easiest way to do this is to join the elements of the list into a single string. You need to separate the elements using a character that can not appear in any of the elements of any list. For example, if the ':' character does not appear in any element, you can do this: for my $listref ( @$seen_ref ) { my $key = join(':',@$listref); $hash{$key}++; } The keys of %hash will then represent the unique lists. It helps a lot if you post a complete, short program that illustrates the problem you are having. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/