Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort a hash as keys in an array

Tags:

perl

I have a hash

%value
g=>10
i=>55
k=>4
n=>100

I have an array

@letters = ('k','i','n','g')

please let me know how to sort my hash in the order of keys in the array.

like image 435
user2441289 Avatar asked Jan 14 '23 05:01

user2441289


1 Answers

If you want to print hash values in order in which they appear in @letters array then,

print join ",", @value{@letters};
like image 129
mpapec Avatar answered Jan 24 '23 15:01

mpapec