Hi Shlomi,

> You shouldn't modify an array (@arr1 in this case) while iterating
over it using
> foreach. Otherwise, the results will be unpredictable. One option to
> overcome it is to do:
> 
> [code]
> my @arr1_copy = @arr1;
> 
> while (defined (my $arr1_elem = shift(@arr1_copy))) {
>       # Do something with $arr1_elem
> }
> [/code]

Is the principle you are trying to explain that the foreach loop should
be changed to a while or that it is advisable to make a copy of the
original array? (Or just both? :-) ) I suppose it's all about the
'while' because even if I made a copy of the array but continued with
the foreach I would have the same problems, wouldn't I? Please confirm. 

If not answered to the above question, please explain why it is
advisable to make a copy of the original array? 

Regards,
Nora


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to