knlst8 has asked for the wisdom of the Perl Monks concerning the following question:
I can't get a 'while' loop to work. In addition, I've tried 'for' and 'foreach' loops, and every combination of \g \G and \cg that I can think of. It always finds only the first row tag, and then counts the cells and substitutes for the nth cell in the first row. Any sort of loop that I put around it only makes the substitution in the first row in every pass through the loop. I'm betting there's a really simple answer that I just haven't stumbled on yet. Can anyone here help?#this while loop isn't right, but I don't know what is...; while ($tbltext =~ /<tr.*?>/cg) { $counter = 1; #reset the counter; $tbltext =~ s/(<td.*?\/td>)/ ++$counter == $nth #is this the nth cell? ? "${1}newtext" #if yes, add "newtext" : $1 #otherwise, leave it /ge; $tbltext =~ /<\/tr>/cg; #find the end of the row } #exit the loop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Continuing after replacing nth occurrence
by GrandFather (Saint) on Mar 10, 2009 at 01:57 UTC | |
by knlst8 (Initiate) on Mar 10, 2009 at 11:13 UTC | |
|
Re: Continuing after replacing nth occurrence
by almut (Canon) on Mar 10, 2009 at 02:45 UTC | |
by knlst8 (Initiate) on Mar 10, 2009 at 11:17 UTC |