suneeldv has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Sorting of numbers using arrays
by dasgar (Priest) on Sep 20, 2010 at 05:36 UTC

       I think it is not possible using "SORT" key word.

    Ummm, have you looked at the documentation for sort? It gives examples of doing just what you want to do, which is to sort an array of data. The code below sorts an array in ascending order and descending order using the sort command.

    use strict; use warnings; use Data::Dumper; my (@unsorted) = qw(7 3 2 9 5 18 1 4); my @sorted1 = sort {$a <=> $b} @unsorted; my @sorted2 = sort {$b <=> $a} @unsorted; print Dumper @sorted1; print "---------\n"; print Dumper @sorted2;

       Please forward solution to following mail id-suneeldv@gmail.com

    Hmmm....sorry, but I'll pass on that one. I could be wrong, but I'm not too sure how many (if any) monks will be willing to do that. You just might have to come back to the monastery to see if anyone has posted a solution that you like. In other words, I'm willing share a "solution" to your question, but I'm not willing share with you my personal email address.

Re: Sorting of numbers using arrays
by biohisham (Priest) on Sep 20, 2010 at 06:00 UTC
    I had to downvote you for your lack of effort and thinking that this is a rent-a-coder or something.

    The Perl documentation pages are brimful of timeless and priceless information to begin with, you could as well access that from your own command console, start with typing %perldoc -h to touch ground.


    Excellence is an Endeavor of Persistence. A Year-Old Monk :D .
Re: Sorting of numbers using arrays
by GrandFather (Saint) on Sep 20, 2010 at 10:18 UTC

    On the off chance that you are looking for a way of sorting a subsection of an array (hard to tell as you give no sample code or data) I offer the following:

    use strict; use warnings; my @values = qw(a b c 9 8 7 1 2 3 6 4 5 x y z); @values[3 .. 11] = sort {$a <=> $b} @values[3 .. 11]; print "@values";

    Prints:

    a b c 1 2 3 4 5 6 7 8 9 x y z
    True laziness is hard work
Re: Sorting of numbers using arrays
by Anonymous Monk on Sep 20, 2010 at 07:07 UTC

    Wouldn't it be much easier if you give us the email-address of your teacher instead? That would prevent possible errors when you copy-n-paste our solutions ...

    Note: We at PerlMonks expect some effort by you. We would be glad to help with a specific problem you encountered by trying yourself. However we are not a do-your-homework service. And we don't like to help those who are too lazy to think/google/read manuals themselves.

Re: Sorting of numbers using arrays
by Anonymous Monk on Sep 20, 2010 at 05:46 UTC
    my @sorted = sort @unsorted;

    Consider the sort function.

Re: Sorting of numbers using arrays
by BrimBorium (Friar) on Sep 20, 2010 at 18:56 UTC

    guessing you mean something like

    my @values = qw(1452 6351 5892); # here is some perl code that converts @values to 1245 1356 2589

    of course you can use sort, just together with split and join :)

      No need for split or join in that case...

      map { scalar reverse } @values

        use strict; use warnings; my @values = qw(1452 6351 5892); @values = map { scalar reverse } @values; print "@values ";

        prints 2541 1536 2985, so it's just reverting but not sorting the strings. I just wanted to point ot that you can use sort.