Имеется скрипт статей на моем сайте.
Недавно я решил "прикрутить" к нему комментарии. Написал код, по моему мнению, рабочий. Но при проверке его, работать он отказался. Вот сурс:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI;
$cgi= new CGI;
$action= $cgi->param("action");
$type= $cgi->param("type");
$id= $cgi->param("id");
$nick= $cgi->param("nick");
$comment= $cgi->param("comment");
&addcom if ($action eq "post");
#подпрограмма добавления комментария к статье:
sub addcom {
#
$lt= "<";
$gt= ">";
$nick=~ s/>/>/g;
$nick=~ s/</</g;
$nick=~ s/;;;;;/:::::/g;
$comment=~ s/>/>/g;
$comment=~ s/</</g;
$comment=~ s/;;;;;/:::::/g;
$comment= substr($comment, 0, 512);
$nick= substr($nick, 0, 64);
$comment=~ s/\n/<br>/g;
$comment=~ s/\r//g;
@word= split(/ /, $comment);
foreach $word (@word)
{
if (length($word)> 64)
{
$ok= "BAD";
}
}
#
open OC, ">>articles/$type/$id.comm";
@old = <OC>;
close OC;
($old_nick, $old_comment) = split(/;;;;;/, $old[@old-1]);
if ($old_comment eq $comment)
{
$ok = "BAD";
}
#
if (($ok ne "BAD") and ($comment ne ""))
{
open FC, ">>articles/$type/$id.comm";
$to_base = join("", $nick, ";;;;;", $comment, "\n");
print FC $to_base;
close FC;
}
}
#подпрограмма вывода существующих комментариев:
sub viewcom {
if (-e "articles/$type/$id.comm")
{
open VFC, "articles/$type/$id.comm";
@comments = <VFC>;
close VFC;
foreach $comments (@comments)
{
($nick, $comment) = split(/;;;;;/, $comments);
print "<tr><td>$nick:<br>$comment<br><br></tr></td>\n";
}
} else
{
print "<tr align=center><td><center>Комментариев к данной статье пока нет!</center></td></tr>";
}
}
#если не указан ни раздел, ни номер статьи, выводим список разделов:
if (($id eq "") and ($type eq ""))
{
print "<table width=60% align=center><tr align=center><th>Мои статьи::Разделы</th></tr>";
print "<tr><td><center>";
open TYPES, "articles/types.cfg";
@types = <TYPES>;
close TYPES;
for ($i= @types- 1; $i>=0; $i--)
{
($t, $inf)= split(/;;;;;/, $types[$i]);
print "<a class=artype href=\"articles.pl?type=$t\">", $t, "</a><br>", $inf, "<br>";
}
print "</center></td></tr></table>\n";
}
#если не указан номер статьи, но указан раздел, выводим список статей из этого раздела:
if (($id eq "") and ($type ne ""))
{
print "<table width=60% align=center><tr align=center><th>Мои статьи</th></tr>";
print "<tr><td>";
$b= 0;
while (open $a, "articles/$type/$b.cfg")
{
close $a;
$b++;
}
print "<center>Всего статей в разделе: ", $b, ".<BR></center>";
for ($a= 0; $a< $b; $a++)
{
open $b, "articles/$type/$a.cfg";
@a= <$b>;
close $b;
print "<a href=\"articles.pl?type=$type&id=$a\">", $a[0], "</a><BR>";
}
print "</td></tr></table>\n";
}
#если указан и номер статьи, и раздел, выводим саму статью:
if (($id ne "") and ($type ne ""))
{
print "<table width=60% align=center><tr align=center><th>Мои статьи</th></tr>";
print "<tr><td>";
open ART, "articles/$type/$id.cfg";
@art = <ART>;
close ART;
print "<center><font size=3>", $art[0], "</font></center><BR><BR>";
foreach $line (@art)
{
if ($line ne $art[0])
{
print $line, "<br>";
}
}
print "</td></tr>";
print "<tr align=center><th>Комментарии к статье:</th><tr>\n<tr><td>";
&viewcom;
print "<tr><td><form action=articles.pl method=post>";
print "Ваш ник: <input name=nick><br>";
print "<TEXTAREA ROWS=10 COLS=40 name=comment></TEXTAREA><br>";
print "<input name=action value=post type=hidden>";
print "<input type=submit value=Комментировать>";
print "</form>";
print "</td></tr></table>\n";
}
Проблема вот в чем: при добавлении комментария в папке articles создается файл .comm с помещенным комментарием. Названия у файла .comm почему-то нет, хотя он должен называться так же, как и перемнная $id и находится он должен в папке по названию перменной $type. Этого почему-то не происходит.
Подскажите, пожалуйста, в чем проблема и какое у неё решение?
[perl] А флодер с именем $type уже существует?21.08.04 02:20 Автор: NKritsky <Nickolay A. Kritsky> Статус: Elderman