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?


In reply to a way to do 'sort|uniq' by jch341277

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.