How do I initialize an array to 0?
I have tried this.
my @arr = ();
But it always throws me a warning, “Use of uninitialized value”. I do not know the size of the array beforehand. I fill it dynamically. I thought the above piece of code was supposed to initialize it to 0.
How do I do this?
If I understand you, perhaps you don’t need an array of zeroes; rather, you need a hash. The hash keys will be the values in the other array and the hash values will be the number of times the value exists in the other array:
Output:
To answer your specific question more directly, to create an array populated with a bunch of zeroes, you can use the technique in these two examples: