in reply to Sorting by the value of the inner hash

I'm going to suggest you do the following:

That aside, is it possible that $totalscoreinv{$key1}{key2} is supposed to be $totalscoreinv{$key1}{$key2}?

Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche