[an error occurred while processing this directive] CGI - A free tutorial for the Total Non-Programmer.
CGI - Let's get startedCGI - Introduction to Perl

#********* BEGIN BODY********************

open(LOGFILE, "<guestbook.log");
@entries = <LOGFILE>;
close LOGFILE;

print "<BODY bgcolor=beige>\n";
print "<TABLE>\n";

foreach $line (@entries) {
        @fields = split(/::/,$line);
        print "<TR><TD>$fields[0] $fields[1]<TD>$fields[9]\n";
};

print "</TABLE>\n";

#********* END BODY********************

  • Copy this script to the BODY of the template.txt file.
  • Save it as getlog.cgi,
  • Use your FTP program to upload getlog.cgi to the perltour folder on the server.  (Ascii transfer only)
  • Switch to a Unix prompt, be sure you are in the perltour folder, and type chmod a+rx getlog.cgi
  • Point your browser to http://your.server.name/perltour/getlog.cgi

  •  The screen should turn beige and display a list of all the people and comments you have entered.

    This script is almost exactly the reverse of the previous script.  The guestbook.cgi script on the previous page would get text from the page, combine it into one long line, and add it to guestbook.log.  This script will get a line of text from the guestbook.log file, parse it into individual values, and display them on the screen.  I chose to display only the name and comments for this first example.  It is easier to read this way.

    open(LOGFILE, "<guestbook.log");

    @entries = <LOGFILE>; print "<BODY bgcolor=beige>\n";
    print "<TABLE>\n"; foreach $line (@entries) { @fields = split(/::/,$line); print "<TR><TD>$fields[0] $fields[1]<TD>$fields[9]\n";
    } print "</TABLE>\n";

    That's it.  Now, since this CGI does not need an user information, it does not need to be the ACTION element of a form.  You can create a link to getlog.cgi the same way you would create a link to any other page.  You can even bookmark it.

     

    BACKPassword protection

    Home | WebData - Web Database Software | Javascript | CGI | Consulting | Map Builder | Contact Us | The Press Room