Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Deciding unique elements of an array

by rolfy (Acolyte)
on Sep 14, 2005 at 01:21 UTC ( #491738=note: print w/ replies, xml ) Need Help??


in reply to Re: Deciding unique elements of an array
in thread Deciding unique elements of an array

more simple - well.... yes and no...

#!/usr/bin/perl my @a = ('a', 'b', 'c', 'c' ,'f', 'a', 'd'); my @b = grep (!$_{$_}++, @a);

the 'my @b' line is the solution - it comes up with the correct info, but does involve doing a little work to get to the answer.

It's definitely more simple to write :) but as for processing times etc - I really don't know if it's going to be better or not.

It's a bit nasty to put this in your code without commenting it also, as I've got a few perl friends (none uber perl ppls, but 'know' perl), and none of them understood the intent :)


Comment on Re^2: Deciding unique elements of an array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (17)
As of 2015-07-31 21:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (282 votes), past polls