Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: sorting an array

by hnd (Scribe)
on Jul 10, 2009 at 08:46 UTC ( #778853=note: print w/replies, xml ) Need Help??

in reply to Re: sorting an array
in thread sorting an array

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: sorting an array
by moritz (Cardinal) on Jul 10, 2009 at 08:58 UTC
    even using sort directly works too (i tried it)


    use strict; use warnings; my @array=("ch1","ch11","ch2","ch5","ch55","ch16"); print join(' ', sort @array), "\n"; __END__ ch1 ch11 ch16 ch2 ch5 ch55

    That's not the same order as Selvakumar wants.

      thnx moritz....
      actually i didnt check my output properly before posting the code
      thnx for pointing that out.....
      but why does not sort sorts properly?
      i mean that when i first tested it on
      @dudes=(fred,barney,drona,mihir,ankit); @dudes=sort @dudes; print "@dudes\n";
      it worked (that was a ages ago)
      i'am worst at what do best and for this gift i fell blessed...
      i found it hard it's hard to find well whatever
        Because it sorts by string comparison. If you have a string $a, and another string which is $b = $a . $any_other_string, than the shorter string $a will always sort lexicographic before the longer string.

        If you look into a phone book, you expect Strauss to come before Strausse, so that's what you usually want.

        The only case where this doesn't do what you mean is to when you compare numbers of different length. That's what Perl offers the <=> operator for.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://778853]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2022-01-20 06:28 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (56 votes). Check out past polls.