Extracting unique elements from arrayby koolgirl (Hermit)
|on Sep 28, 2011 at 19:22 UTC||Need Help??|
koolgirl has asked for the wisdom of the Perl Monks concerning the following question:
OK, so I've got an @ with several hundred elements, some of them "batch", some initials, some numbers, all different lengths. I need to extract only the unique elements, and discard double elements.
I discussed a bit ago in CB, was told to use cmp, I'm not understanding how to get the elements of the array, to iterate through $a and $b in a function, all several hundred of them.
So I went to the cookbook, to find a way to count them with a hash. This is what I found:
But it doesn't work. And I haven't even tried adding numbers and such in with the test array yet. Can someone please break this down for me like I'm a two year old...I have never understood the cmp routines in examples, because I don't get how to pass all the hundreds of elements in my @ into to $a and $b to be compared. I understand how it compares after that, just not that first part. Please help me, I'm starting to see green Matrix code running down my eyes....Thanks koolgirl
"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man.." -- George Bernard Shaw