# File: hash1.pl # Title: The hash data structure: Sorting a hash # Author: Mihaela Malita # Dictionary is: quatrefourcinquefivedeuxtwotroisthreeunone # Keys are: quatre cinque deux trois un # Values are: four five two three one # Sorted dictionary after key: cinque deux quatre trois un # Sorted dictionary after value: five four one three two # Declare a hash I'll call it dictionary %Dictionary = (un => one, deux => two, trois => three, quatre => four, cinque => five); @Mykeys = keys %Dictionary; print "\nthe keys are: @Mykeys"; @Myvalues = values %Dictionary; print "\nthe values are: @Myvalues"; @Sorted_dict_key = sort keys %dictionary; print "\nSorted dictionary after key: @Sorted_dict_key"; # same as @Sorted_dict_key = sort @Mykeys; print "\nSorted dictionary after key: @Sorted_dict_key"; @Sorted_dict_val = sort @Myvalues; print "\nSorted dictionary after value: @Sorted_dict_val"; exit;