Hi Anonymous Monk,

Please note. I am not stating that this is the best one there ever was. Just stating that this is the best one I could come up with.

As for the script not working when the biggest number is a negative, here is what I tried

my @array = (-10,30,5,0b1011,7,9,8, -01111,-10,1,-0xFFF,-19923,3,9,-30 +,5,-100,0,-1,0xFF,-3,30,0b1011,3,2,-300,-0xFF,15);

And here is what I get

@array with 28 elements = -10 30 5 11 7 9 8 -585 -10 1 -4095 -1992 +3 3 9 -30 5 -100 0 -1 255 -3 30 11 3 2 -300 -255 15 @sorted with 28 elements = -19923 -4095 -585 -300 -255 -100 -30 -10 + -10 -3 -1 0 1 2 3 3 5 5 7 8 9 9 11 11 15 30 30 255

Even when there are no negative numbers, the script seems to work fine

my @array = (5,3,4,5,5,1,432,4,3,2)

Output:

@array with 10 elements = 5 3 4 5 5 1 432 4 3 2 @sorted with 10 elements = 1 2 3 3 4 4 5 5 5 432

Kindly let me know which numbers did you try in the list when you noticed the issue

As for CPAN having a lot of pre tested and production ready sort functions, I wholehearted agree with that, and I also know that Perl has it's own sort function, which serves the purpose pretty well. I was just doing this to pacify my own curiosity.


In reply to Re: My best attempt at sorting. Kindly suggest improvements/modifications. by pritesh
in thread My best attempt at sorting. Kindly suggest improvements/modifications. by pritesh

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.