Question

I'm using TextWrangler on a Mac to run Perl.

I have a text file that I want to open as an input file to TextWrangler, but I keep getting the error message, Error: cannot open file simap data.txt for reading.

I know my code is correct because it worked on a PC (using Perl Express).

However I don't think I've saved the text file I'm trying to open in the right place. Where should I save it?

Was it helpful?

Solution

Unless you provide a full path to the file, your program will look for it in the current working directory. You can put the file anywhere you like if you write the open call as

open my $fh, '<', '/full/path/to/simap data.text' or die $!;

Or if you want to omit the path and put it in the current working directory, and you don't know where that is, then add

use Cwd 'abs_path';
print abs_path('simap data.text'), "\n";

and you will see where the program will look if you provide just a filename to the open.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top