【问题标题】:Having problems with file input and reading in Windows with Perl使用 Perl 在 Windows 中输入和读取文件时出现问题
【发布时间】:2012-06-06 21:50:15
【问题描述】:

我正在尝试读取与 Perl 脚本位于同一目录中的文件作为输入,并在 Windows 中使用 Perl 读取该文件。

代码:

$inputFile =  getcwd . "/" . <STDIN>;
open (FILE, chomp($inputFile)) or die "Cannot open $inputFile: $!\n";   
@lines = <FILE>;
print "@lines\n";

我得到的错误是:

C:/Documents and Settings/username/workspace/test.pl  No such file or directory

即使该文件在该确切目录中确实以该确切形式存在。我还尝试将“文档和设置”放在引号中。

【问题讨论】:

    标签: windows perl file input io


    【解决方案1】:

    chomp 的返回值不是 chomped 值。将chomp 分解到open 之前,应该没问题。

    顺便说一句,getcwd 是不必要的;当前目录的概念是指在没有完整路径的情况下查找的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      • 2020-05-24
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      相关资源
      最近更新 更多