I am going to take a guess that given sort do_nothing(@in), do_nothing is being parsed as the name of the sort sub, and the (@in) is being parsed as the list to sort on. That's what it appears to be doing from the Deparse output, anyway.

Yes, that's exactly what Deparse shows, and that's my point: why is perl behaving this way. Perhaps the following variant makes the point more forcibly. I have redefined do_nothing to behave like a typical sort sub; the output now is sorted, but note that the sort sub (do_nothing) is being put to work with the syntax do_nothing( @in ):

use strict; sub do_nothing { $a cmp $b } my @in = qw( e n i g m a ); my @out = sort do_nothing( @in ); print "@out\n"; __END__ % perl enigma.pl a e g i m n

the lowliest monk


In reply to Re^2: Perversity of sorts by tlm
in thread Perversity of sorts by tlm

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.