for loop is not going to all array elements
- From: Brandon Hoppe <bhoppe@xxxxxx>
- Date: Wed, 29 Mar 2006 17:08:08 -0600
Hi,
I have a for loop that loops that an array. Inside the for loop, I push more elements onto the array if needed, but the loop is stopping at the original end of the array and not looping thru the new additions.
Basicall, this is what I have:
$line = "-name SSCC34234342 -views ,Data***,Verilog!BREAK!";
@wow = ();
push(@wow, $line);
foreach $inline (@wow) {
print "LINE: $inline\n";
if($inline =~ /SSCC/) {
$newline = $inline;
$newline =~ s/SSCC/BRGS/;
push(@wow, $newline);
}
}
Now this code above works. It prints the line with SSCC and then prints the line with BRGS.
But in a large piece of code, I have a similar loop. Several other things happen inside the loop, so I'm not sure what could be wrong.
As a debug method, just before the end brace of the foreach loop I added a simple foreach loop that prints out all the elements of the @wow array. This prints out all the newly added elements and the original array. So in the case above it prints out the SSCC line and the BRGS line. So the array is correctly updated from what I take, its just that the original foreach loop isn't going to the new element.
Any ideas? I've tried to add as much info as possible. The loop is pretty large and part of a cgi script so its hard to cut out and test just the for loop with a debugger.
.
- Follow-Ups:
- Re: for loop is not going to all array elements
- From: Anno Siegel
- Re: for loop is not going to all array elements
- From: Jim Gibson
- Re: for loop is not going to all array elements
- From: A. Sinan Unur
- Re: for loop is not going to all array elements
- Prev by Date: Re: Perl CGI and Javascript
- Next by Date: Re: for loop is not going to all array elements
- Previous by thread: FAQ 2.12 Which magazines have Perl content?
- Next by thread: Re: for loop is not going to all array elements
- Index(es):