title: Counting elements in a sparse array in Perl
body: <p>How do I get the total items in an array, <em>not</em> the last id?</p>
  <p>None of two ways I found to do this works:</p>
  <pre><code>my @a;
  # Add some elements (no consecutive ids)
  $a[0]= '1';
  $a[5]= '2';
  $a[23]= '3';
  
  print $#a, &quot;\n&quot;; # Prints 23
  print scalar(@a), &quot;\n&quot;; # Prints 24
  </code></pre>
  <p>I expected to get 3...</p>