neb has asked for the wisdom of the Perl Monks concerning the following question:

I am interested in sorting a hash in a different sort of way.... This snippet looks like it should work be me, what am i missing?

foreach my $market (sort { $market_hash->{$a}[1] cmp $market_hash->{$ +b}[1] } keys (%{$market_data}) ) { print "$market,$market_hash->{$market}[1],$average\n"; }
$market_hash is a reference to a hash which has values that are references to arrays. I am interested in sorting the has on the 2nd value in the array that is the value. Any ideas why this doesn't work? ben

Replies are listed 'Best First'.
Re: Sorting a hash of arrays by the seconds value of the array
by runrig (Abbot) on Dec 11, 2001 at 03:46 UTC
    Any sample data, and detail of what's wrong? Any error message? Is the data you're sorting on numeric or character? "doesn't work" is rather vague...
      i think i am an idiot... Looks like it might just be a typo.... market_data should be market_hash