I am in the process of re-designing my website and have ran into a couple of snags. I wrote this script below to be envoked by hyperlinks passing a cgi perameter to the script so the script knows which source code file to grab and show.
#!/usr/bin/perl -w use strict; use CGI qw(param); my $cgi = new CGI; my @param = $cgi->param(); my $path = "/home/master/webroot/newdesign/scripts/"; my @source; error() unless @param; my $full = $path.$param[0]; if (-e $full) { open(FILE, "$full") || error(); @source = <FILE>; close(FILE); print "Content-type: text/html; charset=ISO-8859-1\n\n"; print <<last; <html> <head><title>$param[0]</title> </head> <body bgcolor="#000000" text="#808080" leftmargin="0" marginwidth="0" +topmargin="0" marginheight="0"> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td> last for (@source) { print; print "<br>\n"; } print <<last2; </td> </tr> </table> </body> </html> last2 }else{ error(); } sub error { print "Content-type: text/html; charset=ISO-8859-1\n\n"; print <<end; <html> <head><title>Error!</title> </head> <body bgcolor="#000000" text="#808080" leftmargin="0" marginwidth="0" +topmargin="0" marginheight="0"> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td> There was an error while trying to post script source! </td> </tr> </table> </body> </html> end exit(0); }
Now this script works fine but when this script sends the target script source code to the web browser the cgi source code in the script gets parsed as html code. Is there anyway I can use this method and not have the web browser parse the cgi source code as html code and simply display as text?

Also along the same lines all the scripts source code formatting (spaces, indentation, basically all whitespace) gets stripped from the source code and all source code is aligned with the left margin. This is not as big of a deal but I would like the scripts to keep their formatting after being sent to the browser.

You can see this script in action and actually see the indications I am talking about above in action at the production server link that follows: http://4.46.66.37/master/webroot/newdesign/scripts.htm


www.perlskripts.com

In reply to issues displaying cgi script source? by Elijah

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.