Skip to content

Instantly share code, notes, and snippets.

@BanzaiMan
Last active August 25, 2016 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BanzaiMan/7fceafa1819fb149ac0d7eb3d8137ebb to your computer and use it in GitHub Desktop.
Save BanzaiMan/7fceafa1819fb149ac0d7eb3d8137ebb to your computer and use it in GitHub Desktop.
Why does this Perl one-liner does not drop the last dupe?
$ echo x:x:y:y:z:x:y:z | perl -e 'print join(":", grep { !$seen{$_}++ } split(/:/, scalar <>))'
x:y:z:z
@BanzaiMan
Copy link
Author

It is supposed to remove all duplicate entries in a :-delimited list while preserving the order in which unique components appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment