in reply to How can I create an array that holds number of variables with values?

Your question almost answers itself
my @var = (43, 60, 1..18); # Later... print $var[1], $var[14];
Use an array instead of multiple, distinct variables.

turnstep is right, you don't have to initialize all the variables to zero, just create them where you need them, giving a value at that time.

runrig's code (my @array = map {0} 0..19) works fine here, as well.

  • Comment on Re: How can I create an array that holds number of variables with values?
  • Download Code