in reply to Re: foreach loops
in thread foreach loops
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: foreach loops
by Bilbo (Pilgrim) on May 27, 2002 at 14:23 UTC |
In Section
Tutorials