sort() is an inbuilt function. It returns a sorted version of the array you pass it. If you want to keep that sorted array you need to assign it to an array. This is a lazy way to do it!

When you say sort @d you are actually saying sort { $a cmp $b } @d where $a and $b are magical vars that hold sequential pairs of elements in the sort. You use cmp to get an alphabetic sort and <=> to get a numeric one. If you want reverse the sort order you transpose the $a and $b. You can have very complex code in the block preceeding the sort because you have access to the sequential pairs in $a and $b. The default is { $a cmp $b } which is an ascending order aphabetic sort.

If you want wild, wicked and short look into grep and map in perlman:perlfunc.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: UnPerl-like Code by tachyon
in thread UnPerl-like Code by jerrygarciuh

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.