0

私はPerlの初心者です。Learning PerlModern Perlなどの前者の作品や本を参考に学ぼうとしています。HTML フォームからのデータを解釈してテキスト ファイルに書き込むこのスクリプトを更新しようとしています。私たちのラボでは、これを再起動して実行することに関心があるためです。元のスクリプトは Linux サーバーで使用するために作成されましたが、その後、Linux から Windows サーバーに切り替えました。

エラー メッセージを表示するための管理者アクセス権がないサーバーは、ActivePerl を備えた Windows サーバーです。Perl スクリプトに情報を書き込む場所を伝える Windows の同等のパスを見つけるのに苦労しています。管理者と話すと、イントラネットがE:ドライブにマップされているようですが、これは致命的なエラーではない可能性があります。

データがフォームに入力された後にブラウザでこのスクリプトを実行しようとすると、ジェネリックが返されます。

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.

ヒント、ドキュメント、チュートリアルは大歓迎です。ありがとうございました。

#!C:\perl\bin\perl.exe -w -t

# Good programming practice dictates...
use strict;
use warnings;

# CGI.pm -- makes life easy
#Carp qw(fatalsToBrowser); outputs the error messages to the browser since there is no terminal to output error messages to. Should be removed before script is used in production.
use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";

# Initialize the CGI Interface
my($cgi) = new CGI;

# Print the Header
print $cgi->header();

#The dbmopen call is now de-appreciated. IE: it no longer works
#Kept for archival reasons
#if (! dbmopen(%DB, "/vol/research/docs/old_site_files/eyesignup/data/eyesignup_NEW.dat", 0666))
#   {
#   print "Error -- Cannot open database.\n";
#   exit;
#   }
# Tie is the correct way to do it now. But first we are going to experiment with writing to a flat .txt file.
open (Datastore, '>>',"E:/intranet/sds/research/docs/data.txt") or die "Can't open file: $!";



# Store variables and increment access count for this user
# So param('VARIABLE') is the name of the variables used in the HTML form while $custVARIABLE is the input for the database

my($custFirst) = $cgi->param('firstname');
my($custLast) = $cgi->param('lastname');
my($custGender) = $cgi->param('gender');
my($custAge) = $cgi->param('age');
my($custDiv) = $cgi->param('division');
my($custPhone) = $cgi->param('phone');
my($custEmail) = $cgi->param('email');
my($custEmployee) = $cgi->param('employee');
my($custInternet) = $cgi->param('internet');
my($custwww) = $cgi->param('www');
my($custDemographic) = $cgi->param('demographic');
my($custProjects) = $cgi->param('projectsworked');
my($custExperience) = $cgi->param('experience');
my($custWeekdays) = $cgi->param('Weekdays');

#Kept for archival reasons
#my($custName) = $cgi->param('name');
#my($custGender) = $cgi->param('gender');
#my($custDiv) = $cgi->param('division');
#my($custPhone) = $cgi->param('phone');
#my($custEmail) = $cgi->param('email');
#my($custInternet) = $cgi->param('internet');
#my($custwww) = $cgi->param('www');
#my($custDemographic) = $cgi->param('demographic');
#my($custExperience) = $cgi->param('experience');
#my($custTimes) = $cgi->param('times');
#my($custStudies) = $cgi->param('studies');
#$custTimes =~ s/\r\n/~/g;

#This takes the input and places it into an array, starting with the individual's
@InfoDB = $custFirst."|".$custLast."|".$custGender."|".$custAge."|".$custDiv."|".$custPhone."|".$custEmail."|".$custEmployee."|".$custInternet."|".$custwww."|".$custDemographic."|".$custProjects."|".$custExperience."|".$custWeekdays;
print Datastore (@InfoDB);
print "\n";

#Kept for archivival reasons.
#$DB{$custName} = $custGender."|".$custDiv."|".$custPhone."|".$custEmail."|".$custInternet."|".$custwww."|".$custDemographic."|".$custExperience."|".$custTimes."|".$custStudies;

#Kept for archival reasons. dbmclose is de-appreciated
#dbmclose(%DB);
#Instead use untie. But first we're just going experiment with using a flat storage system.
#untie(%DB);
close (Datastore) or die;

#Now inform the person their data has been saved. This is terribly ancient code so I haven't gotten around to fixing this part yet.
print "Content-type: text/html\n\n";

print "<HTML>
<HEAD>
<TITLE>Thank you!</TITLE>
</HEAD>
<BODY>";

print "<H1><U>Thank You ".$custFirst."\!</U></H1>
<P>We appreciate your assistance.</P>
<HR width=\"75%\">";

print "<P><H3>The following information has been recorded:</H3>
Name: <I>".$custFirst."</I></p><P>
Gender: <i>".$custGender."</i></p><p>
Division: <i>".$custDiv."</i></p><p>
Phone: <i>".$custPhone."</i></p><p>
Email: <i>".$custEmail."</I></p><P>
How often do you use the internet?: <i>".$custInternet."</i></p><p>
How often do you visit the website?: <i>".$custwww."</i></p><p>
Are you familiar with demographic data?: <i>".$custDemographic."</i></p><p>
Do you have work experience in economics, business, or a related field?: <i>".$custExperience."</i></p><p>
Weekdays that you are available: <i>".$custWeekdays."</i></p><p>
";

print "
</BODY>
</HTML>";

私が取り組んでいるいくつかの制限を補うために、いくつかの変更を加えました。たとえば、これが機能するまで一時的にエラーをブラウザに出力します。そして、古いdbmopen呼び出し (もう機能していません) からフラット ファイル ストレージに移動します。

4

5 に答える 5

1

use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";あなたの問題です。

$ perl -wle 'use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";'
syntax error at -e line 1, near "qw(fatalsToBrowser) or"
Execution of -e aborted due to compilation errors.

プログラムがコンパイル中に停止していたため、有用な構文エラーは発生しませんでした。通常、これはログに表示されますが、表示されません。ステートメントにor dieは不要(および構文エラー)があります。useすでにエラーがスローされます。

プログラムをテストするには、実際には、職場のローカルマシンにPerlのコピーが必要です。これを弾薬として使用してください。それでもツールを使用できない場合は、インストーラーを必要としないポータブルバージョンのStrawberryPerlを使用してください。

エラーログにもアクセスする必要があります。管理者に依頼してください。サーバーへのフルアクセスを許可せずに、ログのみにアクセスできる可能性があります。

于 2011-04-05T22:47:46.087 に答える
1

次の行があります。

# Print the Header
print $cgi->header();

さらに下:

#Now inform the person their data has been saved. This is terribly ancient code so I haven't gotten around to fixing this part yet. 
print "Content-type: text/html\n\n";

どちらも同じことをします — 同じ content-type ヘッダーを 2 回出力しています。いずれかのprint呼び出しを削除できます。またheader()CGI.pmドキュメント内のへの参照をざっと見て、他にできることを確認してください。

于 2011-04-05T20:27:41.160 に答える
1

コマンド ラインから CGI.pm スクリプトをデバッグする方法については、いくつかの優れたリソースがあります。

これらのテクニックをご覧になることをお勧めします。

于 2011-04-05T20:35:13.373 に答える
0

また、暗闇の中でのラフな刺し傷として:

open (Datastore, '>>',"E:/intranet/sds/research/docs/data.txt") or die "Can't open file: $!";

私はWindowsの人ではありませんが、Windowsのパス名では、他のほとんどの人が使用することに決めたスラッシュではなく、バックスラッシュを使用していると思います。

呼び出しを修正することに加えてprint、パス名を次のように置き換えることもできます。

E:\intranet\sds\research\docs\data.txt
于 2011-04-05T21:04:47.707 に答える
0

おそらく問題とは何の関係もありませんが、単なる冗長性の問題であるもう1つの提案:

#!C:\perl\bin\perl.exe -w -t

フラグは次の-wものと同じです。

use warnings;
于 2011-04-05T21:15:37.757 に答える