Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: question on...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 6 Topic 11011 of 11509
Post > Topic >>

Re: question on foreach loop

by chas.owens@[EMAIL PROTECTED] (Chas. Owens) May 1, 2008 at 10:30 AM

On Thu, May 1, 2008 at 10:27 AM, Chas. Owens <chas.owens@[EMAIL PROTECTED]
> wrote:
> On Thu, May 1, 2008 at 10:15 AM,  <itshardtogetone@[EMAIL PROTECTED]
> wrote:
>  > Hi Members,
>  >  Can someone explain why the foreach loop did not iterate 10 times.
>  snip
>
> >  foreach (@[EMAIL PROTECTED]
){
>  >     splice @[EMAIL PROTECTED]
>  >     print "printing \@[EMAIL PROTECTED]
 = @[EMAIL PROTECTED]
";
>  >  }
>  snip
>
>  Mucking about with the array being iterated over breaks the iterator.
snip

from perldoc perlsyn or http://perldoc.perl.org/perlsyn.html#Foreach-Loops
       If any part of LIST is an array, "foreach" will get very confused
if
       you add or remove elements within the loop body, for example with
       "splice".   So don't do that.

-- 
Chas. Owens
wonkden.net
The most im****tant skill a programmer can have is the ability to read.
 




 6 Posts in Topic:
question on foreach loop
itshardtogetone@[EMAIL PR  2008-05-01 22:15:36 
Re: question on foreach loop
chas.owens@[EMAIL PROTECT  2008-05-01 10:30:22 
Re: question on foreach loop
chas.owens@[EMAIL PROTECT  2008-05-01 10:27:29 
Re: question on foreach loop
peng.kyo@[EMAIL PROTECTED  2008-05-01 22:31:29 
RE: question on foreach loop
andrew.curry@[EMAIL PROTE  2008-05-01 16:22:35 
Re: question on foreach loop
rob.dixon@[EMAIL PROTECTE  2008-05-01 17:44:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 23 21:01:04 CDT 2008.