Perl Tip Of The Day: “uniq” an Array

I can across a great snippet of code, posted on DZone, that provides a two line solution to uniq an array while maintaining order:

# Input: @list
# Output: @uniqed
 
my %seen;
my @uniqed = grep !$seen{$_}++, @list;

#From TMtm on DZone.com

Popularity: 3% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Leave a Reply

  • Recent Comments

  • Tags

    AACS Adobe Photoshop Elements 6 Apple Apple Lossless C++ C/C++ CNN Customer Service Dell Digikam DRM Firefox FLAC Fortune Fortune-Widget Fortune File Ghosts I-IV Giga-Byte Google Google Analytics Hack Internet Explorer Kernel Kubuntu Lingo Linksys SPA2102 Linux Mandriva Microsoft Nine Inch Nails OpenSuse Parody PC World Performance Perl Plugin Pre-Installed Linux Quote of the Day Restaurant Software Engineering Ubuntu VOIP Widget Wordpress YouTube
  • Stack Overflow

    Gravatar
    Jason Mock
    591r
    39
  •  

    December 2007
    S M T W T F S
    « Nov   Jan »
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031  
  • Archives

  • Categories

  • Books I'm Reading

    ISBN: 0385504225 ISBN: 020161622X ISBN: 0596100469 ISBN: 0321344758