简体   繁体   English

使用Perl在Windows中输入和读取文件时遇到问题

[英]Having problems with file input and reading in Windows with Perl

I am trying to read a file in the same directory as the Perl script as input and read from it in Windows using Perl. 我试图读取与Perl脚本相同的目录中的文件作为输入,并使用Perl在Windows中从中读取。

Code: 码:

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

The error I get is: 我得到的错误是:

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

Even though that file definitely does exist in that exact form in that exact directory. 即使该文件确实存在于该确切目录中的确切形式。 I've also tried putting the "Documents and Settings" in quotes. 我也尝试将“文档和设置”放在引号中。

The return value from chomp is not the chomped value. chomp的返回值不是chomped值。 Factor out the chomp to before open and you should be fine. open之前将chomp排除在外,你应该没事。

The getcwd is needless, by the way; 顺便说一句, getcwd是不必要的; the concept of current directory means where to look in the absence of a full path. 当前目录的概念意味着在没有完整路径的情况下查看的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM