2013-11-15 75 views
1

閱讀這是我的Apache的錯誤日誌:的Perl CGI從txt文件

[Fri Nov 15 08:55:41.771706 2013] [cgi:error] [pid 4292:tid 1500] [client ::1:35659] AH01215: [Fri Nov 15 08:55:41 2013] testaccounts.pl: Could not open accounts.txt: No such file or directory at C:/wamp/www/testaccounts.pl line 42., referer: http://localhost/testaccounts.pl 

我想從一個文件,是在同一目錄作爲我的腳本來讀取。 我正在使用wamp並在我的電腦上在本地主機上運行腳本。

我只想讓我的程序打印文件中的每一行。

在瀏覽器上,它說:

Software error: 
Could not open accounts.txt: No such file or directory at C:/wamp/www/testaccounts.pl line 42. 

這是我的計劃cauing錯誤的部分:

elsif (param('username') and param('password')) #if a user-name and password is typed in 
{ 
$username=(param('username')); 
$password=(param('password')); 
$title = 'Account: ' . $username; 

my $file = 'accounts.txt'; 
open $file or die "Could not open $file: $!"; 

while(my $line = <$file>) { 
    print $line;  

}

我也有嘗試:

my $file = '/accounts.txt'; 
    $file = $dir . $file; 

哪給出me:

Could not open C:/wamp/www/accounts.txt: No such file or directory at C:/wamp/www/testaccounts.pl line 45. 

回答

0

指定文件的完整路徑。當前工作目錄不是腳本所在的目錄(有關詳細信息,請參見Cwd)。

+0

我已經嘗試了你說的並更新了我的答案。你能進一步解釋嗎?謝謝 – user2995563