title: Can I Initialize an Array to a Given Size in Perl?
body: <p>I have a section in my code where I know I will need an array, and I know exactly how many elements that array will need to have. This section of code will be repeated a lot, so I'd could get some very big time savings by first initializing that array to the size I know it will need and then filling it up vs just pushing items on (pushing would be O(n) as opposed to filling up already created spaces, which would be O(1)). </p>
  
  <p>That said, I can't seem to find any elegant way of initializing an array to a given size, and I have no idea why. I know I can do:</p>
  
  <p><code>my @array; $array[49] =0;</code></p>
  
  <p>to get a 50 item array, but that looks really ugly to me and I feel as though there must be a better way. Ideas?</p>