This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Perl and the fly likes Sorting issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Perl
Bookmark "Sorting issue" Watch "Sorting issue" New topic
Author

Sorting issue

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
I have the following categories (1D, 2D, 3D, 2DD, and 3DD) and each one has a 1 to 20 rank associated with them. What is the easiest way to sort the values so they arrange like this :
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10908
    
  12

What have you tried?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
I had copied a line such as :

but it wasn't working exactly as planned, the solution was replacing <=> with cmp.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10908
    
  12

Rob Hunter wrote: the solution was replacing <=> with cmp.

I don't understand this.

regardless...

The first thing you need to do is define how EXACTLY you want things sorted. Posting an example is fine...but it is not a spec.

My guess is that you might need to break each category into components....so "1D 1" needs to be parsed into "1D" and "1". I believe that if you sort on the second part, then do another sort on the first (assuming you are using a stable sort), it will give you want you want.

There may be some tweaks needed on String vs numeric sorts, but again, without details of what you really need, it's hard to say.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Sorting issue
 
Similar Threads
Assignment To An Array Refrence
Master Exam Array question
Multidimensional Arrays
how is this correct
Multi Dimensional Arrays