title: Perl: Load file into hash
body: <p>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. </p>
  
  <p>File contains alphabet with each letter on its own line:</p>
  
  <pre><code>a
  b
  c
  d
  e
  </code></pre>
  
  <p>and etc,.
  When using <strong>array</strong> instead of hash, logic is simple: load file into array and then print each element with corresponding number using some counter ($counter++).</p>
  
  <p>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:</p>
  
  <pre><code>a:1
  b:2
  c:3
  </code></pre>
  
  <p>I've  tried to first create array and then link it to hash using </p>
  
  <pre><code>%hash = @array
  </code></pre>
  
  <p>but it makes my hash non-sortable.</p>