First off the obligatory advice to those new to Perl: always use strictures (use strict; use warnings;)!
Secondly, the obligatory advice to those who haven't yet learned the folly of rolling their own HTML parsing code - Don't. Use CPAN HTML modules instead. In this case you could try HTML::TableExtract and HTML::Table:
use strict; use warnings; use HTML::Table; use HTML::TableExtract; my $tbltext = <<'END_TBL'; <table> <tr><td>1</td><!-- deleted! <td>2</td>!--><td>3</td><td>4</td></tr +> <tr><td>one</td><td>two</td><td>three</td></tr> </table> END_TBL my $tableEx = HTML::TableExtract->new (); $tableEx->parse ($tbltext); my @rows = $tableEx-> rows (); for my $row (@rows) { next if @$row < 3; # Not interested in short rows $row->[2] = 'newText'; } my $tableOut = HTML::Table->new (); $tableOut->addRow (@$_) for @rows; $tableOut->print ();
Prints:
<table> <tr><td>1</td><td>3</td><td>newText</td></tr> <tr><td>one</td><td>two</td><td>newText</td></tr> </table>
In reply to Re: Continuing after replacing nth occurrence
by GrandFather
in thread Continuing after replacing nth occurrence
by knlst8
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |