I've been thinking for a while that there should be a fairly simple way for doing the same thing as the shell idiom:
$ cat file.txt|sort|uniq
Here's what I've come up with to sort a list of phone numbers:
my $l = 0;
map { defined $_ and print "$_\n" }
map { ($_->[1] ne $l)? $l=$_->[1] : undef }
sort { $a->[1] <=> $b->[1] }
map { [s/[\D\n]//g, $_] }
<>;
But you could use it to sort strings just as easily. You probably don't want to use this to sort any really big files.
I'd be interested in knowing if anyone has found other ways to do this...
Update:After reviewing all the other ways to do this I have to let on that I've been playing with Schwartzian transforms lately so that's why mine took this overly complicated form.
The one-liners are great - however, even after doing a super search for %_ I still can't figure out why doing: @_{@telephones}=(); initializes %_ from the array @telephones?