in reply to array initialization
Or if the array already has the length you want, and you want to make every element zero, use:@a = (0) x 143; # 143 zeroes
But often, the best thing to do is just destroy what's in the array:@a = (0) x @a; # every element set to zero
If you undefine the array, and then try to look at the elements, they will be undefined, and an undefined array element behaves like 0 if you use it as a number. For example:undef @a;
This prints 12.undef @a; $z = $a[3] + 12; print $z;
|
|---|