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.
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. Factor out the chomp
to before open
and you should be fine.
The getcwd
is needless, by the way; the concept of current directory means where to look in the absence of a full path.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.