A very basic question, but the answer eludes me: How do I open files in the same directory as my Perl script?

I'm running these scripts from BBEdit and they worked fine under BBEdit 6.5 on OS 9.2. But when I run them under BBEdit 7 on OS 9 or with BBE7.1 in Mac OS X, I get an error when trying to read a file, saying that the file doesn't exist.

I can successfully write files, but they all go to the root volume directory (in OSX). If I move the file I want to read to the root directory, everything works fine.

I tried using File::Spec after reading messages in the [EMAIL PROTECTED] archive, but while I do get lovely paths using it, things still don't work. File::Spec->path(); returns ".", and even if I concatenate that with my filename using File::Spec->catpath(args); I still get bupkiss.

Here's my original script:
<<
#!/usr/bin/perl
print STDOUT "starting...\n";

$path = "sourcefile.txt"; chomp;
$resultpath = "results.txt"; chomp;

#source file
open (SOURCEFILE, $path)
        or die "Couldn't open $path for reading: $!\n";

#results file
open (TARGETFILE, ">> $resultpath")
        or die "Couldn't open $resultpath for writing: $!\n";

... etc snipped....
>>

Thanks for your help.
--Tim


^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Tim Warner mailto:[EMAIL PROTECTED]

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Salty Dog currently at the bottom of the sea.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



Reply via email to