FQDN-aware sorting for hostname fields

Hi,
I would like to see a new sorting order for the hostname fields which respect the domain structure. The FQDN should be sorted with the TLD at highest priority, but the individual names between the dots should be sorted normally.

Example code (ruby):

list = ["host1.example.net", "host2.example.com", "host3.example.net", "host4.location-b.example.com", "host20.example.net", "host5.location-a.example.com"]
list.sort_by {|s| s.split('.').reverse }

Output:
host2.example.com
host5.location-a.example.com
host4.location-b.example.com
host1.example.net
host20.example.net
host3.example.net

A nice extension would be to sort alphanumerically, so host20.example.net comes after host3.example.net

Thanks,
Christian