Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Sorting Question

by JediWizard (Deacon)
on Oct 04, 2004 at 18:48 UTC ( [id://396332]=note: print w/replies, xml ) Need Help??


in reply to Sorting Question

I don't see any sorting going on in this code. What exactly are you trying to sort? If you are trying to sort @list, try this:

@list = sort({$a cmp $b} @list);
May the Force be with you

Replies are listed 'Best First'.
Re^2: Sorting Question
by Roy Johnson (Monsignor) on Oct 04, 2004 at 18:49 UTC
    Which is just the same as @list = sort @list

    Caution: Contents may have been coded under pressure.
      although you may want to actually sort alphabetically (ie case-insensitive) instead of ASCIIbetically:
      @list = sort { lc $a cmp lc $b } @list;

        Which is why it's often a good idea to use locale when sorting. Then you don't have to contort yourself so much to get good sorting results.

        --
        Damon Allen Davison
        http://www.allolex.net

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-19 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found