you are not using the result of your sort, which is stored in the @keys array.

It should presumably be:

Code

print out "Key: $_ and Value: $functions{$_}\n" foreach @keys;

You did not say what the content of your %functions hash is, so using the <=> operator may or may not be right, depending on which type of sort you want (<=> is for sorting data numerically). If you really need alphatetical sort, then use the cmp function instead of <=>.

Your close statement is not doing anything useful since you don't pass it the filehandle. And BTW, you should rather use lexical filehandles and the 3-argument syntax for open, and also check the result of the open statement. Something like this:

The reason none of the other posted solutions on each of the sites worked was because the question/problem was not clearly stated. And, you never gave any info on how the solutions failed to meet your needs. Saying that you always got the "same disorded result" without explaining/showing what results you were getting and how that differed from what you wanted doesn't help us to understand what you needed.

Given the code and question you posted, we all thought you wanted to sort the values. It wasn't until you specifically stated that you wanted to sort the keys that we were able to provide you with a working solution.