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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.