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.


In reply to Re: open file that is not in default directory by Jim
in thread open file that is not in default directory by polycomb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.