读取log文件
print "</table>\n";
#********* end body********************
拷贝以上代码到template.txt文件的body部分。
保存为getlog.cgi。
把getlog.cgi用ftp上传到服务器的perltour文件夹中。
在unix提示符下,进入perltour文件夹,敲入chmod a+rx getlog.cgi。
在浏览器中打开http://your.server.name/perltour/getlog.cgi,屏幕将显示所有用户输入的信息。
这段代码与前面的正相反,它从log文件中读信息。
open(logfile, "<guestbook.log");
打开guestbook.log文件进行输入工作。
@entries=<logfile>;
把文件的内容输入到数组@entries中。
print "<body bgcolor=beige>\n"
;
print "<table>\n";
写html文件的起始部分。
foreach $line(@entries){
对于数组@entries中的每一行。
@fields=split(/::/,$line);
用::分割$line到数组@fields中。
print "<tr><td>$fields[0]$fields[1]<td>$fields[9]\n";
}
在表格中打印数组@fields中的信息。
print "</table>\n";
表格结束。