This article is written for people who, due to compelling circumstances, urgently needed to study Pearl. For me, it became such a circumstance that my computer became a WEB-server, only I, respectively, WEB-master. Learn to take on other people's mistakes is also an experiment, so I advise your concern for your experiment studying Perla.

At once it is necessary to explain, for whom it is all written. If your server is running on a UNIX platform, then we are forced to pronounce your article. I also have Windows NT workstation 4.0 (RUS) plus Service Pack 3. At what time it's time to make a WEB server out of the computer, we rushed to the built-in WEB site services, but hastened to realize that I do not like it (why? ). And then one good-natured individual advised to put Xitami WEB Server from iMatix Corporation ( www.imatix.com ), which also costs this day.

What touches Pearl itself, then here is somewhat more complicated. Having rummaged through various Perl servers (www.perl.org, www.perl.com) we learned that there are so many versions of Perl that it is quite difficult to choose something concrete. At the same time, there are no any intelligible recommendations regarding the election of a particular version. Having tried nearly all versions for Windows, we stopped our election to Active Perl.

Man, spoiled by every Widow truck also Delphi, scribbling programs for Pearl is quite unusual, so I strongly recommend that you install Perl Builder at once. You can take it at www.solutionsoft.com. There lay a thirty-day Demo variety.

Well, I think it's time to go directly to the lesson. In general, the Pearl script, like any other program, works like this:

  1. Receives data
  2. Processes the data
  3. Produces results

You can send data to the script using double methods - GET also POST. The difference between them is that when using GET, the data is idle instantly in the address bar of the browser, napimer:

httр://treagraf.tasur.edu.ru/cgi-bin/price.pl?Category=POWER&Description=varta

In this case, the B_price.pl script takes data in the QUERY-STRING environment variable.

$data=$ENV{'QUERY_STRING'};

When using the POST method, the data is passed to the standard script input. The length of the data block is taken in the variable CONTENT_LENGTH:

read(STDIN,$data,$ENV{'CONTENT_LENGTH'});

Now, these data must be translated into digestible form, because they are encoded.

The standard agreement is the replacement of spaces with signs plus also the encoding of the remaining unacceptable characters using ASCII codes in hexadecimal form, preceded by a sign (%). Example:

http://treagraf.tasur.edu.ru/cgi-bin/B_price.pl?Category=%C2%E8%E4%E5%EE&Description=%E0%E1%E2%E3

It means:

http://treagraf.tasur.edu.ru/cgi-bin/B_price.pl?Category=Видео&Description=абвг

It's better to decode the query string into the main one yourself. On the task "how?" There are a lot of answers that can not be rewritten. I will give only a small sample:

Replace signs (+) with spaces

$query = s/\+/ /g;

Then we replace all combinations of the sign (%), later followed by hexadecimal digits, with the corresponding ASCII character

$query = s/%([0-9A-H]{2})/pack('C', hex($1))/eg;

I use what Perl Builder advises:

#! E:\perl5\bin\perl &GetFormInput; # вызов подпрограммы получения данных $Category = $field{'Category'}; # приобретаем данные из поля Category $Description = $field{'Description'}; # приобретаем данные из поля Description $Page = $field{'Page'}; # приобретаем данные из поля Page

At the end of the script, place the subroutine "transparent" data reading.

sub GetFormInput { (*fval) = @_ if @_ ; local ($buf); if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN,$buf,$ENV{'CONTENT_LENGTH'}); } else { $buf=$ENV{'QUERY_STRING'}; } if ($buf eq "") { return 0 ; } else { @fval=split(/&/,$buf); foreach $i (0 .. $#fval){ ($name,$val)=split (/=/,$fval[$i],2); $val=tr/+/ /; $val= s/%(..)/pack("c",hex($1))/ge; $name=tr/+/ /; $name= s/%(..)/pack("c",hex($1))/ge; if (!defined($field{$name})) { $field{$name}=$val; } else { $field{$name} .= ",$val"; } } } return 1; }

The second stage of the script's work - finishing the data - is entirely up to you. Check the received data for correctness, write them to a file, do what you want.

And, in the end, you need to give some results to the browser of the customer, and so that the browser correctly displays them. That is, you need to output the results in HTML. This is done simply: (also possible in different ways)

print 'Content-type: text/html', "/n/n"; #обязательная строка print 'Content-type: text/html', "/n/n"; #обязательная строка print '

In the Category field, you typed: ', $ Category,'

', "\ N"

All this touches the scripts that receive data from the form on the HTML page. At the same time the page with the form is separate, the script is separately. It is possible to make it more beautiful also more conveniently: to unite a page also a script in a single whole. For this, the script is written according to the following scheme:

  1. At the main startup, the script draws an HTML page with a form also a link in the ACTION tag to itself. The first run is determined by the lack of input data.
  2. If the input data is, then we get them, we process it, and we also give out the results.

Example:

#! E:\perl5\bin\perl if (($ENV{'QUERY_STRING'} eq '') or ($ENV{CONTENT_LENGTH}=0) ) { # генерируем страницу с формой } else {# приобретаем данные, обрабатываем также выдаем результат}

Guest book

The general algorithm of the guest book is as follows:

1. if a visitor wants to record in a book, then
1.1 Getting the data
1.2 Write them to a file or to a database
1.3 We say thank you to HTML also recommend reading other entries
2. If the visitor wants to honor entries in the book, then
2.1 Reading records from a file or from a database
2.2 Displaying them beautifully in HTML

For the convenience of perception, we designed points 1 also 2 separate scripts add_guestbook.pl also read_guestbook.pl respectively. Messages of the guest book are stored in a text file line by line, i.e. For each entry is a string. This is done for the convenience of reading this file. An example of one record:

Sat Dec 5 13:31:20 1998 & Natasha & student & Good & For the source well. Successes in this field to you, Alexander !&[email protected]

Here is the description of the fields of the guestbook in question.
Name - name, surname, patronymic, nickname - at the discretion of the visitor
Work - profession, family of occupations
RadioButton - three buttons: like (Good), did not like (Bad), pofigu (Different)
Text - text box comments and notes
Email - return address

Add_guestbook.pl - entry in the book

#! e:\perl5\perl # Первая строка, как обычно require "ssi-pl.pl"; # Я использую навигационную панель в виде SSI-включения. Для этого используется модуль ssi-pl.pl if (($ENV{'QUERY_STRING'} eq '') or ($ENV{CONTENT_LENGTH}=0) ) { # если нет входных данных, то генерируем страницу с формой print < <head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><meta name="GENERATOR" content="Microsoft FrontPage 3.0"><title>Книга жалоб также предложений</title></head><body background="../images/background_new.jpg"><div align="left"><table border="0" width="630" height="49"> <tr> <td width="200" height="45"></td> <td width="430" height="45"><p align="center"><img src="../images/guestbook.GIF" alt="Книга жалоб" WIDTH="258" HEIGHT="60"></td> </tr></table></div><div align="left"><table border="0" width="630" height="53" cellspacing="0" cellpadding="0"> <tr> <td width="200" height="260" valign="top"> <p align="center">HTML DoInclude("_menu.htm"); # Это SSI-включение навигационной панели. print <<HTML; </p> <p align="left"> </td> <td width="10" height="53" valign="top"></td> <td width="410" height="53" valign="top"><table border="1" width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="100%"><form name="GuestBook" method="POST" action="add_guestbook.pl"> <div align="left"><p><small>Я, <input type="text" name="Name" size="20"></small>, <small>по профессии бесхитростный </small><input type="text" name="Work" size="20">, <small>посетив этот сервер также ознакомившись с представленными на нем материалами, хочу выразить свои чувства , эмоции следующими приличными словами:</small></p> </div><div align="left"><p><small> </small><input type="radio" value="Good" checked name="RadioButton"><small>мне понравилось Smile happy </small></p> </div><div align="left"><p><small> </small><input type="radio" name="RadioButton" value="Bad"><small>мне никак не понравилось Smile sad </small></p> </div><div align="left"><p> <input type="radio" name="RadioButton" value="Different"><small>мне пофигу :-| </small></p> </div><div align="left"><p><small>В дополнение к сказанному хочу так же сказать: </small></p> </div><div align="left"><p><textarea rows="4" name="Text" cols="30"></textarea></p> </div><div align="left"><p><small>Прошу принять к рассмотрению мое заявление также незамедлительно принять мерки. Решение по моему заявлению направить письменно на мой электрический адрес </small><input type="text" name="Email" size="20"><small>.</small></p> </div><div align="center"><center><p><input src="../images/send.JPG" name="Send" alt="Послать" border="0" type="image" WIDTH="53" HEIGHT="21"> <a href="read_guestbook.pl"><img src="../images/read.jpg" alt="Почитать" border="0" WIDTH="63" HEIGHT="21"></a></p> </center></div> </form> </td> </tr> </table> </td> <td width="10" height="53" valign="top"></td> </tr></table></div></body></html>HTML die; } # Нынче приобретаем входные данные. &GetFormInput; $Name = $field{'Name'} ; $Work = $field{'Work'} ; $RadioButton = $field{'RadioButton'} ; $Text = $field{'Text'} ; $Email = $field{'Email'} ; $Send = $field{'Send'} ; # это поле никак не используется # Проверяем, заполнены ли обязательные поля. # если нет - генерируем HTML страницу с прошением заполнить нужные поля. if ($Name eq '' || $Email eq '' || $Text eq '') { print <<HTML; Content-type: text/html <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><meta name="GENERATOR" content="Microsoft FrontPage 3.0"><title>Книга жалоб также предложений - ошибка</title></head><body background="../images/background_new.jpg"><div align="left"><table border="0" width="630" height="49"> <tr> <td width="200" height="45"></td> <td width="430" height="45"><p align="center"><img src="../images/guestbook.GIF" alt="Книга жалоб" WIDTH="258" HEIGHT="60"></td> </tr></table></div><div align="left"><table border="0" width="630" height="53" cellspacing="0" cellpadding="0"> <tr> <td width="200" height="260" valign="top"><p align="center">HTML DoInclude("D:/InetPub/wwwroot/_menu.htm"); print <<HTML; </p> <p align="left"> </td> <td width="10" height="53" valign="top"></td> <td width="410" height="53" valign="top"><p align="left"><small>Вы никак не указали свое имя, E-mail, или никак не заполнили самолично текст Вашего отзыва. Вернитесь, пожалуйста, на страницу формы также заполните требуемые поля.</small></p> <p align="center"><a href="add_guestbook.pl">Назад</a> </td> </tr></table></div><table> <tr> <td width="10" height="53" valign="top"></td> </tr></table></body></html>HTML } else # все данные правильно введены { # если все поля заполнены правильно, то затеваем их обрабатывать. $Text=tr/\r\n/ /; #заменяем перевод строки на пробел # если в текстовом поле формы (text box) посетитель нажимал Enter, # то нужно убрать символы перевода строки, чтобы можно было записать # все поля формы в одну строку файла. if ($Work eq '') {$Work=' '}; #если пусто - то пробел # если поле никак не заполнено, то оно равно пробелу. $Name=s/&/ /g; $Work=s/&/ /g; $Text=s/&/ /g; $Email=s/&/ /g; # если посетитель использовал символ &, то заменяем его на пробел, # поскольку этот символ мы будем использовать для деления наших полей в файле. open(OutFile, ">>guestbook.txt") || die; # Вскрываем файл для прибавления. $Time=localtime; #получаем время # Получаем пора заполнения гостевой книги. $line=join('&', $Time, $Name, $Work, $RadioButton, $Text, $Email, $ENV{REMOTE_HOST}); # И, в конце концов, слепляем все поля формы в одну строку. На каждый приключение добавляем в конце # IP адрес посетителя, взятый из переменных окружения. print OutFile "$line\n"; close OutFile; # Записываем полученную строку в файл также закрываем его. # Осталось только сказать посетителю спасибо. # выводим сообщение о успехе print "Content-type: text/html\n\n"; print "<html>\n" ; print "\n" ; print "<head>\n" ; print '<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">'."\n" ; print '<meta name="GENERATOR" content="Microsoft FrontPage 3.0">'."\n" ; print "<title>Книга жалоб также предложений</title>\n" ; print "</head>\n" ; print "\n" ; print '<body background="../images/background_new.jpg">'."\n" ; print '<div align="left">'."\n" ; print "\n" ; print '<table border="0" width="630" height="49">'."\n" ; print " <tr>\n" ; print ' <td width="200" height="45"></td>'."\n" ; print ' <td width="430" height="45"><p align="center">'; print '<img src="../images/guestbook.GIF" alt="Книга жалоб" WIDTH="258" HEIGHT="60"></td>'."\n" ; print " </tr>\n" ; print "</table>\n" ; print '</div><div align="left">'."\n" ; print "\n" ; print '<table border="0" width="630" height="53" cellspacing="0" cellpadding="0">'."\n" ; print " <tr>\n" ; print ' <td width="200" height="260" valign="top"><p align="center">'."\n" ; DoInclude("D:/InetPub/wwwroot/_menu.htm"); print ' <p align="left"> </td>'."\n" ; print ' <td width="10" height="53" valign="top"></td>'."\n" ; print ' <td width="410" height="53" valign="top"><p align="center"><small>Ваши данные'."\n" ; print " приняты. Спасибо.</small></p>\n" ; print ' <p align="center"><a href="read_guestbook.pl">'; print '<img src="../images/read.jpg" alt="Почитать" border="0" WIDTH="63" HEIGHT="21"></a> </td>'."\n" ; print " </tr>\n" ; print "</table>\n" ; print "</div>\n" ; print "\n" ; print "<table>\n" ; print " <tr>\n" ; print ' <td width="10" height="53" valign="top"></td>'."\n" ; print " </tr>\n" ; print "</table>\n" ; print "</body>\n" ; print "</html>\n" ; } # Не забываем подпрограмму разбора данных из формы. sub GetFormInput { (*fval) = @_ if @_ ; local ($buf); if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN,$buf,$ENV{'CONTENT_LENGTH'}); } else { $buf=$ENV{'QUERY_STRING'}; } if ($buf eq "") { return 0 ; } else { @fval=split(/&/,$buf); foreach $i (0 .. $#fval){ ($name,$val)=split (/=/,$fval[$i],2); $val=tr/+/ /; $val= s/%(..)/pack("c",hex($1))/ge; $name=tr/+/ /; $name= s/%(..)/pack("c",hex($1))/ge; if (!defined($field{$name})) { $field{$name}=$val; } else { $field{$name} .= ",$val"; #if you want multi-selects to goto into an array change to: #$field{$name} .= "\0$val"; } } } return 1; } #! e:\perl5\perl # Первая строка, как обычно require "ssi-pl.pl"; # Я использую навигационную панель в виде SSI-включения. Для этого используется модуль ssi-pl.pl if (($ENV{'QUERY_STRING'} eq '') or ($ENV{CONTENT_LENGTH}=0) ) { # если нет входных данных, то генерируем страницу с формой print < <head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><meta name="GENERATOR" content="Microsoft FrontPage 3.0"><title>Книга жалоб также предложений</title></head><body background="../images/background_new.jpg"><div align="left"><table border="0" width="630" height="49"> <tr> <td width="200" height="45"></td> <td width="430" height="45"><p align="center"><img src="../images/guestbook.GIF" alt="Книга жалоб" WIDTH="258" HEIGHT="60"></td> </tr></table></div><div align="left"><table border="0" width="630" height="53" cellspacing="0" cellpadding="0"> <tr> <td width="200" height="260" valign="top"> <p align="center">HTML DoInclude("_menu.htm"); # Это SSI-включение навигационной панели. print <<HTML; </p> <p align="left"> </td> <td width="10" height="53" valign="top"></td> <td width="410" height="53" valign="top"><table border="1" width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="100%"><form name="GuestBook" method="POST" action="add_guestbook.pl"> <div align="left"><p><small>Я, <input type="text" name="Name" size="20"></small>, <small>по профессии бесхитростный </small><input type="text" name="Work" size="20">, <small>посетив этот сервер также ознакомившись с представленными на нем материалами, хочу выразить свои чувства , эмоции следующими приличными словами:</small></p> </div><div align="left"><p><small> </small><input type="radio" value="Good" checked name="RadioButton"><small>мне понравилось Smile happy </small></p> </div><div align="left"><p><small> </small><input type="radio" name="RadioButton" value="Bad"><small>мне никак не понравилось Smile sad </small></p> </div><div align="left"><p> <input type="radio" name="RadioButton" value="Different"><small>мне пофигу :-| </small></p> </div><div align="left"><p><small>В дополнение к сказанному хочу так же сказать: </small></p> </div><div align="left"><p><textarea rows="4" name="Text" cols="30"></textarea></p> </div><div align="left"><p><small>Прошу принять к рассмотрению мое заявление также незамедлительно принять мерки. Решение по моему заявлению направить письменно на мой электрический адрес </small><input type="text" name="Email" size="20"><small>.</small></p> </div><div align="center"><center><p><input src="../images/send.JPG" name="Send" alt="Послать" border="0" type="image" WIDTH="53" HEIGHT="21"> <a href="read_guestbook.pl"><img src="../images/read.jpg" alt="Почитать" border="0" WIDTH="63" HEIGHT="21"></a></p> </center></div> </form> </td> </tr> </table> </td> <td width="10" height="53" valign="top"></td> </tr></table></div></body></html>HTML die; } # Нынче приобретаем входные данные. &GetFormInput; $Name = $field{'Name'} ; $Work = $field{'Work'} ; $RadioButton = $field{'RadioButton'} ; $Text = $field{'Text'} ; $Email = $field{'Email'} ; $Send = $field{'Send'} ; # это поле никак не используется # Проверяем, заполнены ли обязательные поля. # если нет - генерируем HTML страницу с прошением заполнить нужные поля. if ($Name eq '' || $Email eq '' || $Text eq '') { print <<HTML; Content-type: text/html <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><meta name="GENERATOR" content="Microsoft FrontPage 3.0"><title>Книга жалоб также предложений - ошибка</title></head><body background="../images/background_new.jpg"><div align="left"><table border="0" width="630" height="49"> <tr> <td width="200" height="45"></td> <td width="430" height="45"><p align="center"><img src="../images/guestbook.GIF" alt="Книга жалоб" WIDTH="258" HEIGHT="60"></td> </tr></table></div><div align="left"><table border="0" width="630" height="53" cellspacing="0" cellpadding="0"> <tr> <td width="200" height="260" valign="top"><p align="center">HTML DoInclude("D:/InetPub/wwwroot/_menu.htm"); print <<HTML; </p> <p align="left"> </td> <td width="10" height="53" valign="top"></td> <td width="410" height="53" valign="top"><p align="left"><small>Вы никак не указали свое имя, E-mail, или никак не заполнили самолично текст Вашего отзыва. Вернитесь, пожалуйста, на страницу формы также заполните требуемые поля.</small></p> <p align="center"><a href="add_guestbook.pl">Назад</a> </td> </tr></table></div><table> <tr> <td width="10" height="53" valign="top"></td> </tr></table></body></html>HTML } else # все данные правильно введены { # если все поля заполнены правильно, то затеваем их обрабатывать. $Text=tr/\r\n/ /; #заменяем перевод строки на пробел # если в текстовом поле формы (text box) посетитель нажимал Enter, # то нужно убрать символы перевода строки, чтобы можно было записать # все поля формы в одну строку файла. if ($Work eq '') {$Work=' '}; #если пусто - то пробел # если поле никак не заполнено, то оно равно пробелу. $Name=s/&/ /g; $Work=s/&/ /g; $Text=s/&/ /g; $Email=s/&/ /g; # если посетитель использовал символ &, то заменяем его на пробел, # поскольку этот символ мы будем использовать для деления наших полей в файле. open(OutFile, ">>guestbook.txt") || die; # Вскрываем файл для прибавления. $Time=localtime; #получаем время # Получаем пора заполнения гостевой книги. $line=join('&', $Time, $Name, $Work, $RadioButton, $Text, $Email, $ENV{REMOTE_HOST}); # И, в конце концов, слепляем все поля формы в одну строку. На каждый приключение добавляем в конце # IP адрес посетителя, взятый из переменных окружения. print OutFile "$line\n"; close OutFile; # Записываем полученную строку в файл также закрываем его. # Осталось только сказать посетителю спасибо. # выводим сообщение о успехе print "Content-type: text/html\n\n"; print "<html>\n" ; print "\n" ; print "<head>\n" ; print '<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">'."\n" ; print '<meta name="GENERATOR" content="Microsoft FrontPage 3.0">'."\n" ; print "<title>Книга жалоб также предложений</title>\n" ; print "</head>\n" ; print "\n" ; print '<body background="../images/background_new.jpg">'."\n" ; print '<div align="left">'."\n" ; print "\n" ; print '<table border="0" width="630" height="49">'."\n" ; print " <tr>\n" ; print ' <td width="200" height="45"></td>'."\n" ; print ' <td width="430" height="45"><p align="center">'; print '<img src="../images/guestbook.GIF" alt="Книга жалоб" WIDTH="258" HEIGHT="60"></td>'."\n" ; print " </tr>\n" ; print "</table>\n" ; print '</div><div align="left">'."\n" ; print "\n" ; print '<table border="0" width="630" height="53" cellspacing="0" cellpadding="0">'."\n" ; print " <tr>\n" ; print ' <td width="200" height="260" valign="top"><p align="center">'."\n" ; DoInclude("D:/InetPub/wwwroot/_menu.htm"); print ' <p align="left"> </td>'."\n" ; print ' <td width="10" height="53" valign="top"></td>'."\n" ; print ' <td width="410" height="53" valign="top"><p align="center"><small>Ваши данные'."\n" ; print " приняты. Спасибо.</small></p>\n" ; print ' <p align="center"><a href="read_guestbook.pl">'; print '<img src="../images/read.jpg" alt="Почитать" border="0" WIDTH="63" HEIGHT="21"></a> </td>'."\n" ; print " </tr>\n" ; print "</table>\n" ; print "</div>\n" ; print "\n" ; print "<table>\n" ; print " <tr>\n" ; print ' <td width="10" height="53" valign="top"></td>'."\n" ; print " </tr>\n" ; print "</table>\n" ; print "</body>\n" ; print "</html>\n" ; } # Не забываем подпрограмму разбора данных из формы. sub GetFormInput { (*fval) = @_ if @_ ; local ($buf); if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN,$buf,$ENV{'CONTENT_LENGTH'}); } else { $buf=$ENV{'QUERY_STRING'}; } if ($buf eq "") { return 0 ; } else { @fval=split(/&/,$buf); foreach $i (0 .. $#fval){ ($name,$val)=split (/=/,$fval[$i],2); $val=tr/+/ /; $val= s/%(..)/pack("c",hex($1))/ge; $name=tr/+/ /; $name= s/%(..)/pack("c",hex($1))/ge; if (!defined($field{$name})) { $field{$name}=$val; } else { $field{$name} .= ",$val"; #if you want multi-selects to goto into an array change to: #$field{$name} .= "\0$val"; } } } return 1; }

That's all. An example of the described script can be found at http://treagraf.tasur.edu.ru/cgi-bin/add_guestbook.pl

Read_guestbook.pl - reading a book

#! e:\perl5\perl # Первая строка, как обычно require "ssi-pl.pl"; # Я использую навигационную панель в виде SSI-включения. Для этого используется модуль ssi-pl.pl open(InFile, "guestbook.txt") || die; # Вскрываем файл с записями гостевой книги. @lines=<InFile>; # Читаем строки в массив. # Выдаем шапку HTML страницы. print <<HTML; Content-type: text/html <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><meta name="GENERATOR" content="Microsoft FrontPage 3.0"><title>Книга жалоб также предложений - нам пишут</title></head><body background="../images/background_new.jpg"><div align="left"><table border="0" width="630" height="49"> <tr> <td width="200" height="45"></td> <td width="430" height="45"><p align="center"><img src="../images/guestbook.GIF" alt="Книга жалоб" WIDTH="258" HEIGHT="60"></td> </tr></table></div><div align="left"><table border="0" width="630" height="53" cellspacing="0" cellpadding="0"> <tr> <td width="200" height="260" valign="top"><p align="center"><small>HTML DoInclude("D:/InetPub/wwwroot/_menu.htm"); print <<HTML; </p> <p align="left"> </td> <td width="10" height="53" valign="top"></td> <td width="410" height="53" valign="top"><p align="center">Нам пишут:</p> <table border="0" width="100%" cellspacing="0" cellpadding="0">HTML # Нынче выводим записи в невидимой (в смысле, рамка никак не видима) таблице. # Чтобы свежие записи отображать первыми, обрабатываем массив строк с конца. for ($i=$#lines; $i>=$[; $i--) #обрабатываем строки файла с конца { # Делим строку на элементы @item=split('&', $lines[$i]); #разделяем на элементы # Нынче заменяем HTML тэги в записи (на приключение какого-нибудь хитрого юзера) foreach (@item) { $_=s/</</g; $_=s/>/>/g; } # Приступаем непосредственно к заключению записей в HTML print "<tr>\n"; print '<td width="100%"><dl>'."\n"; # В зависимости от поля, в каком месте посетителю предлагался избрание понравилось - никак не понравилось, # рисуем картинку с радостной либо грустной мордочкой соответственно. В качестве ALT тэга # картинки пропишем IP адрес посетителя. print '<dt><img src="../images/'.$item[3].'.gif" width="31" height="31" alt="'; priny $item[6].'" align="absbottom"'."\n"; # Выводим остальные поля. print 'align="absmiddle"><small>'.' '.$item[4]."</small></dt>\n"; print '<dt><small>'.$item[1].', '.$item[2]."</small></dt>\n"; print '<dt><a href="mailto:'.$item[5].'"><small>'.$item[5].'</small></a></dt>'."\n"; print '<dt><small>'.$item[0]."</small></dt>\n"; print "</dl>\n"; print "</td>\n"; print "</tr>\n"; } # Осталось вывести окончание HTML print <<HTML; </table> </td> <td width="10" height="53" valign="top"></td> </tr></table></div></body></html>HTML close InFile; # Закрываем файл с записями гостевой книги.