Your code is overwriting the contents of an already existing array, I wouldn't call that initialising ...# Initialise an array so that $array[n] = n my $n = 0; foreach (@array) {$_ = $n++}
Putting that aside, an array slice is a good way to do that task without using a loop.
@array[0..100] = 0..100; # or to mimic the behaviour of your code exactly @array[0..$#array] = 0..$#array;
-- Hofmator
In reply to Re: Re: foreach loops
by Hofmator
in thread foreach loops
by root
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |