in reply to Trouble with loops
foreach my $name (@array){ print "$name "; if($name eq 'joby'){ shift(@array); print "deleted\n"; next; } print "ok\n"; }
Your problem is that you're modifying the array you're iterating over. Just don't do that with a foreach loop :)
(This issue comes up from time to time, so if you search this site you should find rather extensive related discussion... (e.g. self-feeding infinite loop))
|
|---|