When I have such a problem in foreign code and cannot locate it easily (because the code is badly structured), I insert diagnostic messages. You can send them to client or to the error log of the webserver (print STDERR). So you maybe can debug, if this part of code is reached, how some variables are set.

If you can still not locate, because the code is deeply nested (Spaghetti Code), then you can factor out subroutines for element groups. Each of the subroutines calls the subroutines for child content, and includes the child content between the opening and closing HTML tags.

sub invoice { my $invoice_data = shift; my $items_html = invoice_items($invoice_data->{items}); my $invoice_number = $invoice_data->{number}; my $html = <<HTML; <div class="invoice"> <div class="invoice_no">$invoice_number</div> <div class="invoice_items"> $items_html </div><!-- END invoice_items --> </div><!-- END invoice --> HTML return $html; }

Of course you could also attach HTML comments for BEGIN and END like in the above example. So you can see in the HTML source where the closing div comes from or which is missing.

With the above small subroutines you can be sure, that they are properly closed. I use these often to repair bogus code. This method which I call "microtemplates" can be applied partially. And the code is fast.


In reply to Re: How to get diagnostic information for a web app when nothing is written to the error log by wollmers
in thread How to get diagnostic information for a web app when nothing is written to the error log by ted.byers

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.