in reply to Hash sorting (by value) woes
This is a good situation for using a Schwartzian Transform. The code you have is close to right, but it's confusing and hard to follow a bit, partly because of all that logic in the sort block that isn't really part of the sorting. I'd move the regex matching out to a preliminary map, put just the sorting code in the sort block, and then map back to the part you want in the upper map...
my @sortedkeys = map { $$_[0] } sort { $$a[1] <=> $$b[1] } map { $$etcpw{$_} =~ /[:](\d+)/; [$_, $1] } keys %$etcpw;
Much easier to follow, if you ask me. As far as why your original code doesn't work, I think it's because pattern matches don't do the same thing in scalar context as they do in array context.
|
|---|