0

I'm iterating through a hash and printing the output to a HTML file in perl.

Currently I'm able to print to the HTML file but the text characters are getting printed out of the table row for a particular field called - FILES.

For certain values there are multiple file paths for the field "FILES", hence data is getting printed out of the table.

In HTML how can I limit the content or the table data to be printed within the Row.

I tried using the wrap but of no use:

<td wrap>$$val{Files}</td>

and

<td nowrap>$$val{Files}</td>

I want the extended files or path to get fit in to the particular cell without flowing out of the row.

Below is my piece of code:

foreach $prg (keys %work) {
    print FH "<font color = #000000> <font size = 4> <u><center><br/>Design: <b>$prg</b></center></u></font>\n";

    foreach $jir (keys %{$work{$prg}}) {
      print FH "<p><font color = #000000><b>DESIGN ID:$jir</b></font></p> ";
        @myarr = @{$work{$prg}{$jir}};
        foreach $val (@myarr) {
            print FH "<body><table border=1 width=100% style='table-layout:fixed'></body>\n";

            print FH "<col width=6%> <col width=5%><col width=10%><col width=15%><col width=10%><col width=50%>";

            print FH "<tr bgcolor=##4169E1><th><font color = #FFF5EE>Design_ID</th><th><font color = #FFF5EE>Submitter</th><th><font color = #FFF5EE>Reviewer</th><th><font color = #FFF5EE>Description</th><th><font color = #FFF5EE>Date</th><th><font color = #FFF5EE>Files</th></tr>\n";

             print FH "<tr bgcolor=#FFF8C6 border=1><td>$$val{design}</td><td>$$val{Initial}</td><td>$$val{Reviewer}</td><td bgcolor=#FFF8C6>$$val{Description}</td><td>$$val{time}</td><td>$$val{Files}</td></tr>\n";
             print FH "</table>\n";
            }
    }
}
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
voltas
  • 553
  • 7
  • 24
  • Try this http://stackoverflow.com/questions/28642049/limit-the-character-in-html-column `word-break: break-all; word-wrap:break-word;` – AbhiNickz Aug 26 '16 at 11:01
  • As well as the top answer in [this](http://stackoverflow.com/questions/15405817/truncating-text-inside-a-div) – Drav Sloan Aug 26 '16 at 11:04
  • Thank you @AbhiNickz & Drav Sloan for your inputs – voltas Aug 26 '16 at 11:41
  • Have you heard about [XSS attacks](https://en.wikipedia.org/wiki/Cross-site_scripting)? Your code does not seem to protect against malicious data injected in `%work`. – dolmen Aug 30 '16 at 11:03

1 Answers1

0

welcome to Stack Overflow.

You can possibly solve this by using CSS. Which can either be used by using an external stylesheet or inline style tag.

For example (as seen in CSS text-overflow in a table cell?)

td {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

Though looking at your code, I think you might refactor or cleanup your HTML. I'm not experienced with Perl but guessing from other languages.

The body tag should only be used once per HTML file/output. The font and center tags are deprecated in favor of CSS. I thought col was not an element at all, but seems it had just been deprecated for a long time. Having such errors in your HTML might lead to unexpected rendering issues as well.

Community
  • 1
  • 1
Maarten Bicknese
  • 1,498
  • 1
  • 14
  • 27