open FILE2,'output.txt';
But with no mode specified, this defaults to reading (i.e., input mode), so each attempt to print to the file results in an error message like this:
print() on closed filehandle FILE2 at ...
As a general rule, you should prefer the three-argument form of open with the mode made explicit:
open FILE, '<', 'testFile.txt';
...
open FILE2, '>', 'output.txt';
And, as Laurent_R says, you should always check whether the open call succeeds. If you don’t want to write ... or die ... after each call, you can simply add the pragma:
use autodie;
at the head of your script. See autodie.
Hope that helps,
|