in reply to Initialize a 2D array with zeros

Do you want a fast solution or a nice solution? I would create a string $str = ''; and do vec($str, 999999, 8) = 0; This is probably the fastest way to initialize a table (not to mention it's also the most memory-efficient solution as well.) This will initialize an "array" of characters 1000 x 1000. To access any value in this array, simply do this: vec($str, $Y*1000+$X, 8) where $X and $Y are the coordinates of your char array. If you need an array of integers, simply change the number 8 to 16 (or 32 for an array of 32-bit integers.)

EDIT: To make it slightly more efficient, the "width" of your array should be a power of 2. So, instead of 1000 x 1000, you'd create 1024 x 1000, and then you would access any value in the array by doing this instead:    vec($str, $Y << 10 | $X, 8)    The only difference is that now we use the bitwise << shift operator and | OR operator in the calculation instead of multiplication and addition. When you use multiplication, Perl assumes that you're multiplying a 64-bit double, so it executes the FMUL function which is slow. But when you do bitwise operations, your calculation is classified as integer math which is way faster, especially when you have to do millions of calculations.