Date: Tue, 26 Jun 2001 16:08:36 GMT From: "Irfan Baig" Subject: Re: how to sort array of similar hashes by one of the hash keys? Message-Id: <20010626.120746.1308044878.29810@irf.local> Never mind, I found out - if anyone needs to know : @sorted_game = sort{ $b->{'score'} <=> $a->{'score'} } @game; In article <20010626.113916.1096689772.29810@irf.local>, "Irfan Baig" wrote: > I've split data from a flatfile into hashes in an array, @game, all of > which have keys 'name', 'score' and 'date'. > > @game = (); > for ($i=0; $i<=$#scores; $i++){ > ($game[$i]{'name'},$game[$i]{'score'},$game[$i]{'date'}) = split(/,/, > $data[$i]); > } > > I'm now trying to sort the array by comparing the values of the 'score' > elements in each array's hash. Is this possible? I've tried some > combinations such as: > > @sorted_game = sort{ $game[$a]{'score'} <=> $game[$b]{'score'} } @game; > > but no luck. Can someone help me out?