[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] an elegant uniquing



I've got an array full of anonymous hashes, each with 4-6 keys.  I would
like to create a few arrays containing uniqued values from one of those
keys, across all the hashes.

This is a neat one-line trick I got from the Cookbook:

 @unique = grep { ! $seen{ $_ }++ } @not_unique;
  
which I assumed I could adapt to my needs:

 @unique_names = grep { ! $seen{ ${$_}{names}++ } @array_of_hashes;
 
which works, in that I get the right number of elements, but fails in
that my new @u_names array is full of hash references, and not stringy
hash values.  grep is returning "$_", not "${$_}{names}" as I intended.

Is there a way to do this in one line?

  -nat

-- 
Nat Irons           |  873D 7978 23FC 37FE 10D5  | "Which" is deletable
lexical@bumppo.net  |  349A F57F 0FAA F4D4 B19A  |  and nonrestrictive

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org