Turn perl or C program listings into html with line numbers. Link header, module, data or other files to the source.

I use this all the time for my own hompage when I try to get help with programs I am writing. Let me know what you think.

WEBIFY.PL
#!/usr/bin/perl use Text::Tabs; $tabstop = 4; $target = shift @ARGV; open ( FILE, "<$target"); chomp ( @code = <FILE> ); close FILE; foreach $line (@code) { $line =~ s/\</&#60;/; $line =~ s/\>/&#62;/; $line = expand ($line); } unshift @code, "<ol>"; unshift @code, "<code>"; while (@ARGV) { # add links to page # use filename description $linkname = shift; $linkdescrip = shift; $link_html = qq\ <a href="$linkname">$linkdescrip</a>< +br>\; print "Link = $link_html \n"; unshift @code, $link_html; } unshift @code,"<body>"; unshift @code,"<title> $target </title>"; unshift @code, "<html>"; push @code, "</ol>"; push @code, "<" . "/code>"; # split to fool PM formatting! push @code, "</body>"; push @code, "</html>"; open (FILE,">".$target.".html"); $body = 0; foreach $line (@code) { if ( ( $line =~ m/^#.*/) || ( $line =~ m/^\/\*/ ) || ( $line =~ m/^[a-zA-Z0-9_]/) ) { $body = 1; } if ($line =~ m/^\<\/ol\>/) { $body = 0; } if ($body) { print FILE "<LI>".$line."\n"; } else { print FILE $line."\n"; } } close FILE;

In reply to webify by talwyn

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.