if your text file already has (literal) <h1>, etc, why don't you just copy it to a new file and rename that foo.htm? (You'll probably have to add at least minimal html headers and close the heading tags, but that's a different script). For most in-house purposes that occur to me (insufficient imagination may be a work here), that would be fairly simple.

If your output is intended for the global population of the web, please reconsider nesting tables.

Most current browsers don't exact the kind of speed penalties we saw under NS 4 and IE5 (data lacking for Konqueror, Safari, etc), but there is still some... and another for failure to specify width ... preferably with css (tho, personally, because my logs tell me there are still quite a few users of NS4.7, IE 5.0, etc., I stick widths (as %) in <table... and <td elements to cope with those browsers' poor/flaky handling of css and inheritance.

If your H1, 2, 3 are intended to resemble classic 7th grade outlining", the suggestions above look sensible; if you're not dealing with a simple outline, you probably should consider someting like:

open (test that its open: use die!!!) and read original file into array
open a filehandle (OFH) for output (and test)
print OFH "<html><head><title>$1</title></head><body><table><tr>";
(where $1 is the orig filename)
foreach $line(@array) { print OFH "<td>$line</td></tr><tr><td>"; } print OFH "/td></tr></table></body></html>"; close, etc...

This will keep the <Hn tags from your original, though neither approach I've mentioned will keep the indentation.

add newlines to taste if you're going to need to read/tweak the html


In reply to Re: convert text to HTML Format Table. by ww
in thread convert text to HTML Format Table. by perlsen

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.