• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

convert text file into html table

I have files with documentation information which i would like to put into a table, but i don't want to do it manually.  The files looks something like
             SECTION_KEY char (15) NOT NULL ,
             TERM char (5) NOT NULL ,
             CALL_NUMBER varchar (9) NULL ,
             DEPT char (4) NULL ,
             COURSE char (4) NULL ,
             SEC char (2) NULL ,
             TITLE varchar (32) NULL ,
             UNITS decimal(8, 2) NULL ,
             ACTIVITY1 char (3) NULL ,
 I want to have, for example section_key in column 1, char in column 2 and (5) in column 3.
Do i need a program to make this happen, and if so i would like to a code sample for that or something very similar.          
0
xoxomos
Asked:
xoxomos
  • 2
1 Solution
 
ozoCommented:
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print "<html><head><title>convert text file into html table</title></head><body><table>";
while( <DATA> ){
    print '<tr><td>';
    print join'</td><td>',/(\w+)\s*(\w+)\s*(\([^)]*\))(.*)/;
    print "</td></tr>\n";
}
print "</table></body></html>\n";
__DATA__
             SECTION_KEY char (15) NOT NULL ,
             TERM char (5) NOT NULL ,
             CALL_NUMBER varchar (9) NULL ,
             DEPT char (4) NULL ,
             COURSE char (4) NULL ,
             SEC char (2) NULL ,
             TITLE varchar (32) NULL ,
             UNITS decimal(8, 2) NULL ,
             ACTIVITY1 char (3) NULL ,
0
 
xoxomosAuthor Commented:
Could you explain the 'print join' line?
thanks
0
 
ozoCommented:
perldoc -f join

    join EXPR,LIST
            Joins the separate strings of LIST into a single string
            with fields separated by the value of EXPR, and returns
            the string. Example:

                $_ = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now