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
chompis not the chomped value. Factor out thechompto beforeopenand you should be fine.The
getcwdis needless, by the way; the concept of current directory means where to look in the absence of a full path.