【问题标题】:Perl cgi read from txt filePerl cgi 从 txt 文件中读取
【发布时间】:2013-11-17 00:53:32
【问题描述】:

这是我的 Apache 错误日志:

[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.

这是我的程序导致错误的部分:

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;

这给了我:

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

【问题讨论】:

    标签: perl cgi


    【解决方案1】:

    指定文件的完整路径。当前工作目录不是脚本所在的目录(详见Cwd)。

    【讨论】:

    • 我已经尝试了你所说的并更新了我的答案。你能进一步解释一下吗?谢谢
    猜你喜欢
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多