While we always appreciate someone taking the time to present an easy to digest model of their problem domain, in this case the devil is in the details. And that is you really have data that is HTML. A good rule of thumb is to not parse and alter HTML with regular expressions. Doesn't mean you can't and it does not mean you should not ... it just means that if you take the time now to provide a more proper solution, you will more than likely save yourself and others time and pain down the road. Having said that ... pretty much everything that renders HTML these days will ignore empty <tr> groupings for you. Are you sure you really need to do anything at all?
UPDATE: wouldn't this be a more robust solution for your needs? (moved my example data to code block below)
use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new( twig_handlers => { tr => \&prune_tr }, pretty_print => 'indented', ); $twig->parse( \*DATA ); $twig->print; sub prune_tr { my ($handler, $tr) = @_; $tr->delete unless $tr->children; } __DATA__ <table> <tr> <td>ZZZ</td> <td>YYY</td> <td>XXX</td> </tr> <tr> </tr> <tr> <td>FFF</td> <td>SSS</td> <td>GGG</td> </tr> <tr> </tr> <tr> <td>WWW</td> <td>EEE</td> <td>TTT</td> </tr> </table>
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Re: file alteration
by jeffa
in thread file alteration
by artperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |