Dec 4, 2010, 5:35 PM
Post #1 of 4
Initializing an array with a specific value
I'm a novice at Perl Programming. I have a quick question.
I'd like to make an array of size 1000, and I want each element to be initialized to one.
A simple approach that I can think of is just using the for-loop.
@array = ();
for (my $i = 0; $i < 1000; $i++)
$array[$i] = 1;
However, the above code does not look elegant. Could anyone tell me what would be an efficient way of doing this?
Thank you in advance!