Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ
îðèãèíàëüíîãî äîêóìåíòà
: http://www.sao.ru/cats/~satr/perl/perl_8.shtml
Äàòà èçìåíåíèÿ: Sat Jun 24 18:06:10 2000 Äàòà èíäåêñèðîâàíèÿ: Tue Oct 2 01:16:06 2012 Êîäèðîâêà: koi8-r Ïîèñêîâûå ñëîâà: massive stars |
Ïîìèìî ãîñòåâîé êíèãè îñíîâíûì àòðèáóòîì ñåðüåçíîãî Web-óçëà ÿâëÿåòñÿ ñïèñîê ðàññûëêè íîâîñòåé. Perl-ïðîãðàììà äëÿ âûïîëíåíèÿ ðàññûëêè äîâîëüíî ïðîñòà, ïðè æåëàíèè åå ìîæíî íåñêîëüêî óëó÷øèòü, äîáàâèâ íîâûå âîçìîæíîñòè (ñì. ëèñòèíã 9).
Ïðè ñîçäàíèè Web-óçëà, îðèåíòèðîâàííîãî êàê íà ðóññêîÿçû÷íûõ, òàê è íà àíãëîÿçû÷íûõ ïîñåòèòåëåé, â ïðîãðàììå ïðåäóñìîòðåíà âîçìîæíîñòü âûäà÷è ñîîáùåíèé â ñîîòâåòñòâóþùåì âèäå. Îñíîâíàÿ ôîðìà (ðèñ. 3) â çàâèñèìîñòè îò ÿçûêà óçëà äîëæíà îáÿçàòåëüíî ñîäåðæàòü ïîëå:
èëè
äëÿ ðàñïîçíàâàíèÿ ÿçûêà âûäà÷è ñîîáùåíèé.
×òîáû îáëåã÷èòü ðàçáîð ïðîãðàììû ðàññûëêè íîâîñòåé, â íåé ðàññòàâëåíû êîììåíòàðèè.
Ëèñòèíã 9. Ñïèñîê ðàññûëêè íîâîñòåé #!/usr/local/bin/perl ############################ # SCRIPT: POSTER.CGI # # (c) Michael Yevdokimov # ############################ require ‘cgi_lib.pl’; $PathList=”../mlist”; #ôèçè÷åñêèé ïóòü ê êàòàëîãó ñ áàçîé ïîñåòèòåëåé $PathNews=”../mnews”; #ôèçè÷åñêèé ïóòü ê êàòàëîãó ñ äîêóìåíòîì äëÿ ïîñûëêè $ReturnPage=”index.html” #ñòðàíèöà, ê êîòîðîé íóæíî áóäåò âîçâðàòèòüñÿ $mail_prog=”/usr/sbin/sendmail”; #ôèçè÷åñêèé àäðåñ ê ïî÷òîâîé ïðîãðàììå $Title=”News List”; #çàãîëîâîê ñïèñêà ðàññûëêè $From=”maillist\@mysite.ru”; #àäðåñ ñïèñêà ðàññûëêè $Website=”www.mysite.ru”; #èñòî÷íèê ñïèñêà ðàññûëêè äëÿ Subject # Method Detection and Decoding &Parse_Data; # äåêîäèðîâàòü äàííûå èç ôîðìû / URL $Lang=$CGI{‘lang’}; # òèï ÿçûêà (Ðóñ/Àíãë) $User=$CGI{‘user_name’}; # èìÿ ïîñåòèòåëÿ $Email=$CGI{‘user_email’}; # email ïîñåòèòåëÿ $Flag=$CGI{‘flag’}; # ôëàã äëÿ ïðîâåðêè íåêîòîðûõ óñëîâèé â ïðîãðàììå $Command=$CGI{‘command’}; # ñ÷èòàòü êîìàíäó (send èëè ‘’) if ($Lang eq ‘english’) { $db=”userbase.eng”; # áàçà ñ èíîñòðàííûìè ïîäïèñ÷èêàìè $nf=”news.eng” # àíãëèéñêàÿ ”ïîñûëêà” (îáû÷íûé TXT) } else { if ($Lang eq ‘russian’) { $db=”userbase.rus”; ” ñ ðîññèéñêèìè ïîäïèñ÷èêàìè $nf=”news.rus”; ðóññêàÿ ”ïîñûëêà” (îáû÷íûé TXT) } else { &Print_Head; # àíàëîãè÷íî print ”Content-type:text/html\n\n”; print ”ATTENTION! ERROR OCCURED!
\n”; print ”PRESS [BACK] TO RETURN!\n”; exit(0); } } if ($Command eq ‘send’) { # ïðîâåðêà òîé ñàìîé êîìàíäû if ($db eq ‘userbase.eng’) { #Post English News &Post_News($User,$Email); } else { #Post Russian News &Post_News($User,$Email); } } #Ïðîâåðèòü çíà÷åíèå àòðèáóòà flag if ($Flag eq ‘eng_yes’) { # åñëè èíôîðìàöèÿ âåðíà &Check_Email; # âûçâàòü ïîäïðîãðàììó ïðîâåðêè ââåäåííîãî email &Add_Record($Path,$db); # äîáàâèòü çàïèñü â ñîîòâåò. áàçó &Print_Head; print ”Your records were added to database
\n”; print ”Click here to return...\n”; exit(0); } else { if ($Flag eq ‘rus_yes’) { &Check_Email; &Add_Record; &Print_Head; print ”Âàøè äàííûå çàíåñåíû â áàçó äàííûõ
\n”; print ”Íàæìèòå çäåñü äëÿ âîçâðàòà...\n”; exit(0); } else { } } # âûâåñòè ôîðìó ïîäòâåðæäåíèÿ ïðàâèëüíîñòè ââåäåííîé èíôîðìàöèè if ($db eq ‘userbase.eng’) { #Àíãëèéñêèé âàðèàíò ôîðìû &Print_Head; print ”
News List Registration
\n”; print ”\n”; print ”
\n”; print ”\n”; } else { #Ðóññêèé âàðèàíò ôîðìû &Print_Head; print ”
\n”; print ”
\n”; print ”
\n”;
print ”\n”;
}
sub Add_Record { # ïîäïðîãðàììà çàïèñè ïîñåòèòåëåé â ÁÄ
open (UB, ”>>$PathList/$db”) || die (”Error during adding a record $!”);
print UB join (”::”, ”$User”, ”$Email”), ”\n”;
close (UB);
}
sub Post_News { # ïîäïðîãðàììà ðàññûëêè íîâîñòåé
#Îòêðûòü UB - áàçó ïîëüçîâàòåëåé
open (UB, ”$PathList/$db”) || die (”Error during
reading file $!”);
while ( \n
Email: $Email
which you have entered is incorrect! \n
PRESS [BACK] TO RETURN\n”;
return $ErrMsg;
} else {
$ErrMsg=”ÂÍÈÌÀÍÈÅ! ÂÎÇÍÈÊËÀ ÎØÈÁÊÀ! \n
Email: $Email,
êîòîðûé âû ââåëè íåïðàâèëåí! \n
ÍÀÆÌÈÒÅ [BACK] ÄËß ÂÎÇÂÐÀÒÀ\n”;
return $ErrMsg;
}
}
Íàçàä |
Ñîäåðæàíèå |
Âïåðåä