Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Is there an easy way to assign guaranteed unique values to a simple array without looping through whole array?

by mreece (Friar)
on Nov 30, 2007 at 02:26 UTC ( #654029=note: print w/replies, xml ) Need Help??


in reply to Is there an easy way to assign guaranteed unique values to a simple array without looping through whole array?

if i understand correctly, you can do it with an intermediate hash and grep.
my %seen; my @nodupes = grep { not $seen{$_}++ } @mayhavedupes;
as for whether you consider grep "having to loop" or not, well, it's a lot less loopy than sorting keys...
  • Comment on Re: Is there an easy way to assign guaranteed unique values to a simple array without looping through whole array?
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2021-01-18 01:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?