Re: for loop is not going to all array elements
- From: Jim Gibson <jgibson@xxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Mar 2006 17:23:05 -0800
In article <e0f40o$7nc$1@xxxxxxxxxxxxxxx>, Brandon Hoppe
<bhoppe@xxxxxx> wrote:
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);
}
}
Why don't you copy the array first, then iterate over the array adding
lines to the copy as needed (untested):
push(@wow, $line);
my @wow2 = @wow;
foreach $inline (@wow) {
print "LINE: $inline\n";
if($inline =~ /SSCC/) {
$newline = $inline;
$newline =~ s/SSCC/BRGS/;
push(@wow2, $newline);
}
}
Do you need to reprocess the lines added?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
.
- References:
- for loop is not going to all array elements
- From: Brandon Hoppe
- for loop is not going to all array elements
- Prev by Date: Re: Arbitrarily Many Nested Loops
- Next by Date: FAQ 2.14 Where are the archives for comp.lang.perl.misc?
- Previous by thread: Re: for loop is not going to all array elements
- Next by thread: Re: for loop is not going to all array elements
- Index(es):