Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Sorting based on a specific order

by PeterPeiGuo (Hermit)
on Jan 02, 2011 at 06:27 UTC ( [id://880053]=note: print w/replies, xml ) Need Help??


in reply to Sorting based on a specific order

Here is one solution: use a hash to store the predetermined order - teacher's name as the key and the value could be an integer that determines the order.

Peter (Guo) Pei

Replies are listed 'Best First'.
Re^2: Sorting based on a specific order
by ikegami (Patriarch) on Jan 02, 2011 at 07:37 UTC
    my @order = ...; my %order = map { $order[$_] => $_ } 0..$#order; my @sorted = sort { $order{$a} <=> $order{$b} } @unsorted;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found