From: oadartse@... (Osuka) Date: 2003-07-01T19:07:55+09:00 Subject: Sorting a Hash I'm Having some trouble sorting a hash!, the hash contents are like this: 1 is Ayumi Hamasaki 2 is Zone 1 is Two-Mix 2 is Shazna 1 is L'arc~en~ciel Problem is: I want to ordered it in a descending order but using Hash.invert I lose data 'cos there can't be several keys that are the same, so any ideas of how to do this this is the code the comments are there 'cos they del some data ---------------CODE------------------------ jdir="E:/emusic/jrock" Dir.chdir(jdir) jlist=Array.new jlist=Dir.entries(jdir) jlist.sort! $serie=Array.new $jcount=Hash.new() jlist.each do |entry| $serie=entry.sub(/ - +[a-zA-Z0-9\-.!=&+~\(\) ']*/,'') if($jcount.has_key?($serie)) $jcount[$serie]=$jcount[$serie]+1 else $jcount.store($serie,1) end end #$jcount=$jcount.invert #$jcount=$jcount.sort #$jcount.reverse! $jcount.each {|key, value| print value, " is ", key, "\n" } ---------------CODE------------------------ comments on the regexp are also welcomed "artist - name(~=live'now-now'~[what])-.mp3" to "artist"