home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5884 < prev    next >
Encoding:
Text File  |  1992-09-11  |  1.0 KB  |  31 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!snorkelwacker.mit.edu!paperboy.osf.org!meissner
  3. From: meissner@osf.org (Michael Meissner)
  4. Subject: Re: Removing duplicates from an array
  5. In-Reply-To: tmhoff@oogoody.Corp.Sun.COM's message of 11 Sep 1992 22:30:25 GMT
  6. Message-ID: <MEISSNER.92Sep11224350@curley.osf.org>
  7. Lines: 17
  8. Sender: news@osf.org (USENET News System)
  9. Organization: Open Software Foundation
  10. References: <lb27g1INNaef@jethro.Corp.Sun.COM>
  11. Date: Sat, 12 Sep 1992 02:43:54 GMT
  12. Lines: 17
  13.  
  14. In article <lb27g1INNaef@jethro.Corp.Sun.COM>
  15. tmhoff@oogoody.Corp.Sun.COM (Todd Hoff) writes:
  16.  
  17. | Is there a cool way of removing duplicates from an array? I can think
  18. | of several methods, it could be an option on sort, but what is the
  19. | perl way?
  20.  
  21. I would think an associtive array:
  22.  
  23.     %foo = ();
  24.     @array = grep ($foo{$_}++ == 0, @array);
  25.     %foo = ();
  26. --
  27. Michael Meissner    email: meissner@osf.org        phone: 617-621-8861
  28. Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142
  29.  
  30. You are in a twisty little passage of standards, all conflicting.
  31.