I'm struggling to understand logic behind hashes in Perl. Task is to load file in to hash and assign values to keys which are created using this file.
File contains alphabet with each letter on its own line:
a
b
c
d
e
and etc,. When using array instead of hash, logic is simple: load file into array and then print each element with corresponding number using some counter ($counter++).
But now my question is, how can I read file into my hash, assign automatically generated values and sort it in that way where output is printed like this:
a:1
b:2
c:3
I've tried to first create array and then link it to hash using
%hash = @array
but it makes my hash non-sortable.
$counter++? - ASCIIThenANSI$counteralso should be a value for keys in my hash which are represented as letter:key -> a, value -> 1, key - > b, value -> 2. - user4839151