in reply to Re^4: How do I sort an array by hash value?
in thread How do I sort an array by hash value?

Here is how I failed:
@id = sort { $lid->{split(/=/, $a)} cmp $lid->{split(/=/, $b)} } @id;

Near to success:

@id = sort { $lid->{(split(/=/, $a))[0]} cmp $lid->{(split(/=/, $b))[0 +]} } @id;

This line has to evaluate $a and $b each time sort does a comparison, which isn't efficient. I guess that ikegami's line neither is.

Should be used a temporary translation hash? Something like:

my %temp = map { $_ => (split(/=/, $_, 2))[0] } @id; @id = sort { $lid->{$temp{$a}} cmp $lid->{$temp{$b}} } @id;