Re: sort an array unique.



On Jan 31, 10:43 am, Robert 'phaylon' Sedlacek <r...@xxxxxx> wrote:
Paul Lalli wrote:
On Jan 31, 9:23 am, "rajendra" <rajendra.pra...@xxxxxxxxxxxx> wrote:
Is there any command to sort an array uniquelly,something similar to
"sort -u" in unix.

Not built-in, but it's fairly easy to implement:

JFYI, it's also in List::MoreUtils as 'uniq'.

http://search.cpan.org/dist/List-MoreUtils/lib/List/MoreUtils.pm

Huh, so it is. For some reason, I'd forgotten about that. So my
short example gets even further reduced to:
$ perl -MList::MoreUtils=uniq -le'
my @unsorted_with_dups = qw/d a e c b e d a c b e a b c e d/;
my @sorted_uniques = sort(uniq(@unsorted_with_dups));
print "@sorted_uniques\n";
'
a b c d e

Thanks for the reminder,
Paul Lalli

.



Relevant Pages

  • Re: What is the maximal length of usernames on Solaris?
    ... You've just made the determination that eight characters is it ... >> that this is a reason not to try and change it. ... >> I don't know how many times I've been preaching the merits of UNIX to ... >for updating all the apps and spending it on his bonus. ...
    (comp.sys.sun.admin)
  • Re: ????Dragon Lady???
    ... >>reason it's been done here, but it's not the only reason. ... Guess it is case dependant huh? ... >>> I have put a couple of people's real names on my Kook site who normally go ... because they've been posting my real name here. ...
    (alt.support.chronic-pain)
  • Re: Programmer knowledge
    ... >> Every IBM PC shipped with an MS OS, and later virtually every IBM PC ... Or a Unix variant. ... Is that part of Windowsor part of the applications though? ... This is a case of someone choosing, for whatever reason, to write ...
    (comp.programming)
  • Re: Mac Servers - a real joke
    ... The real reason corporations stick with Windows is a specific type of ... Blade servers in large farms run the Internet ... Many of those run Linux or Unix. ... OSX is based on Unix, ...
    (comp.sys.mac.advocacy)
  • Re: Mac Servers - a real joke
    ... more the fact that the software selection ... The real reason corporations stick with Windows is a specific type of ... Blade servers in large farms run the Internet ... Many of those run Linux or Unix. ...
    (comp.sys.mac.advocacy)