B
Brandon Hoppe
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 ,Datasheet,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.
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 ,Datasheet,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.