2011-04-05 2 views
0

저는 Perl 초보자입니다. 나는 이전의 사람의 작품과 책을 기초로하여, Learning PerlModern Perl과 같은 것을 배우려고 노력하고 있습니다. HTML 폼의 데이터를 해석하고 텍스트 파일에 쓰는이 스크립트를 업데이트하려고합니다.이 작업을 다시 시작하고 다시 실행하는 데 실험실에 관심이 있기 때문입니다. 원본 스크립트는 Linux 서버에서 사용하기 위해 작성되었지만 Linux에서 Windows 서버로 전환했습니다.내 플랫 파일 텍스트 파일의 경로가 잘못 되었습니까? 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 호출 (더 이상 작동하지 않음)에서 플랫 파일 저장소로 이동하십시오.

답변

1
:

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

-w 플래그는 같은 일이 같다

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. 

프로그램이 컴파일 중일 때 죽어 가고 있으므로 유용한 구문 오류가 발생하지 않습니다. 일반적으로 로그에서이를 볼 수는 있지만 그렇게 할 수는 없습니다. use 문에서는 or die이 필요하지 않으며 구문 오류가 발생합니다. 이미 오류가 발생합니다.

로컬 컴퓨터에 Perl 복사본이 있어야 실제로 프로그램을 테스트 할 수 있습니다. 이것을 탄약으로 사용하십시오. 그래도 도구를 사용할 수 없으면 설치자가 필요없는 휴대용 버전 Strawberry Perl을 사용하십시오.

또한 오류 로그에 액세스해야합니다. 관리자에게 물어보십시오. 서버에 대한 완전한 액세스 권한없이 로그에 액세스 할 수 있습니다.

+0

감사합니다. Strawberry Perl의 휴대용 버전을 사용하여 스크립트를 테스트합니다. 설치에 관리자 권한이 필요하지 않으므로 괜찮을 것입니다. 내가 이런 일을 한 적이 한 번도 없었기 때문에 내 상황이 조금 이상했다. (따라서 제한된 능력과 오류 로그와 같은 것들에 대한 접근). 그것은 내가 추가 업무 책임으로 일하도록 자신을 왜곡해야하는 것 중 하나 일뿐입니다. 감사! – OneBigNewbie

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"; 

모두 같은 일을 - 당신이 두 번 같은 콘텐츠 형식 헤더를 인쇄 할 수 있습니다. 하나 또는 다른 전화 print을 제거 할 수 있습니다. 또한 CGI.pm docs에있는 header()에 대한 참조를 통해 가능한 다른 것들을 살펴보십시오.

+0

감사합니다. 코드를 디버깅 할 때 시도한 것 중에 하나를 추가했다고 생각합니다 (헤더가 없으면 perl이 터미널에 출력 됨). 하나 또는 다른 하나를 제거하려고했지만 여전히 작동하지 않습니다. : – OneBigNewbie

+0

그게 사실이 아니에요. 명령 줄에서 스크립트를 실행할 수 있으며, 헤더를 표준 출력으로 보내면 헤더는 텍스트 일뿐입니다. 스크립트를 다음과 같이 분할하여 문제를 해결하십시오. 더 작은 조각을 얻을 때까지 작동합니다. 그런 다음 스크립트 조각을 다시 넣고 문제의 원인을 찾을 때까지 다시 실행하십시오. –

1

명령 줄에서 CGI.pm 스크립트를 디버깅하는 방법에 대한 몇 가지 좋은 자원이 있습니다

내가 당신을 제안 이 기법을 살펴보십시오.

+0

감사합니다. 직장에서 ActivePerl 또는 StrawberryPerl에 액세스 할 수 없습니다 (아 .. 제한된 환경에서 작업하는 즐거움) 집에서 컴퓨터에 설치하고 집에서 디버깅 해보 아야합니다. 기술에 대한 링크를 제공해 주셔서 감사합니다! – OneBigNewbie

0

또한, 어둠 속에서 거친 자상과 같이

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

앞으로 다른 거의 모든 사람들이에 정착 것을 슬래시 대신에, 나는 윈도우 사람 모르겠지만, Windows의 경로 이름은 backslashes을 사용하여 생각 사용.

print 전화를 고정하는 것 외에도

, 당신은 또한 함께 경로 이름을 바꿀 수 있습니다

E:\intranet\sds\research\docs\data.txt 
+2

Windows는 일반적으로 두 가지 유형의 슬래시를 허용합니다. 하지만, 파일을 여는 데 아무런 문제가 없어야합니다. 모든 도주를해야하는 것을 제외하고는 상처를 입을 수 없습니다 ... – Schwern

0

아마 문제와 아무 상관이 있지만, 중복의 문제입니다하지 않는 또 다른 제안 :

use warnings; 
+2

'사용 경고 '는 어휘 적이기 때문에 범위에 적용됩니다 (in 이 대/소문자, 파일). '-w'는 전체 프로그램에 대한 경고를 켭니다 : 여러분이 사용하는 모든 함수와 라이브러리. 둘 다 작동하도록 상처주지 않습니다. – Schwern

관련 문제