Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Find unique elements in an array

by dragonchild (Archbishop)
on Apr 05, 2004 at 03:14 UTC ( #342560=note: print w/replies, xml ) Need Help??

in reply to Find unique elements in an array

My personal unique'ing function is:
sub unique { my %x; @x{@_} = @_; values %x }

The reason to use values is that I need to get the unique set from an array of objects, not scalars. (This assumes, of course, that every object has a unique stringification. As I don't overload stringification in my objects, this works. If you do overload stringification ... good luck. Seriously.)

And, the reason for not using references is that I use this function as so:

my @final = map { # Something } unique grep { # Something } map { # Something } @start;

We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2020-02-26 18:08 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (117 votes). Check out past polls.