in reply to how to loop through?
#!/usr/bin/perl use strict; use warnings; { local $/='<tr>'; while (my $line = <DATA>){ my $i=0; while ($line =~ m/<tc>/) { $line =~ s!<tc>!'<tc cNum="'.++$i.'">'!ie; #why not insert another substitution in here that handles +the case <tc (colspan="\d+")> ... } print $line; } } __DATA__ <tr><tc>1</tc><tc>2</tc><tc>3</tc></tr> <tr><tc colspan="2">1and2</tc><tc>3</tc></tr> <tr><tc>1</tc><tc colspan="2">2and3</tc></tr> <tr><tc>1</tc><tc>2</tc><tc>3</tc></tr>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to loop through?
by texuser74 (Monk) on Feb 26, 2010 at 08:38 UTC |