in reply to open file that is not in default directory

It didn't seem to open, or it didn't open? :-) What actually happened exactly?

One obvious problem is that you enforce discipline upon yourself and your Perl program, and then you are undisciplined. When you use the use strict pragma, you must then declare your lexical variables with my or else your program won't run.

Here's how I would write the same program in Modern Perl:

#!perl use strict; use warnings; use autodie qw( open close ); my $in_file = 'E:/Perl/Practice/TestIn.txt'; my $out_file = 'E:/Perl/Practice/TestOut.txt'; open my $in_fh, '<:encoding(UTF-8)', $in_file; open my $out_fh, '>:encoding(UTF-8)', $out_file; # Do groovy stuff with the text... close $in_fh; close $out_fh; exit 0;

This assumes your input text file is in the UTF-8 character encoding form of the Unicode coded character set. If it's not, then replace the encoding with whatever the correct encoding is (e.g., Windows-1252).

By the way, it doesn't matter where you run your Perl script from. The only files specified in your program are absolute paths, not relative paths.

Replies are listed 'Best First'.
Re^2: open file that is not in default directory
by polycomb (Initiate) on Jan 17, 2011 at 17:17 UTC

    Thanks, Jim. You are right.