1

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.

0

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.