in reply to what is keys %$hash_ref [-1]

What would be the purpose of getting the last element of a list without sorting the keys (in a corrected statement as shown in other replies)? (OTOH, the original correct code just might have sort in there too.)