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?

It should be as ikegami had it, except the
    $lid->{$a} cmp $lid->{$b}
statement should be
    $lid->{$a_} cmp $lid->{$b_}
(note addition of the trailing underscores).

The  my $a_ = $a; step is so the values in the array aliased by the 'magical' variables  $a and  $b are not changed by the substitutions (i.e., the change you noted).