This could definitely be useful. There are two things I would change though:
  1. The script assumes the input filename only has one dot. If the input file is named "my.first.flat.file.db," the output filename is going to be "my.html." This is not a good thing.
  2. The script doesn't escape characters like &, <, >, etc. This means you have to worry about whether the database contains HTML tags and even JavaScript. What if one of the rows contained something like this: <script language='JavaScript'>window.open ('http://www.hax0rsit3.bogus') ;</script>|column 2|column 3Bam! Instant security hole.

Of course, you can always turn off JavaScript, and maybe you never intended to use the script on untrusted data, but IMO, it's never too early to think about security. Plus, as it stands the script doesn't handle ampersands and angle brackets properly. Why not just write the data to stdout (avoiding the filename issue) and use CGI.pm to format/escape the HTML?

#!/usr/bin/perl -w use strict ; use CGI qw (:standard *table) ; die "Usage: $0 <input-filename-list>\n" unless @ARGV ; binmode STDOUT, ':crlf' ; print start_html (-title => join ('; ', @ARGV)), start_table, "\n" ; while (<>) { tr/\r\n//d ; my @cols = map {escapeHTML ($_)} split '\|' ; print TR (td ([@cols])), "\n" ; } print end_table, end_html ;

I admit the output doesn't look as pretty as your nice hand-formatted output though.


In reply to Re: db2html by blackmateria
in thread db2html by straywalrus

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.