in reply to print() on closed filehandle

You don't check the status of open()ing OUTPUT_FILE. Change your open to read something like:

open (OUTPUT_FILE, ">", $outputfile) or die "Unable to open $outputfile: $!\n";
I've also used the 3-argument form of open().


davis
It wasn't easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.

Replies are listed 'Best First'.
Re^2: print() on closed filehandle
by Win (Acolyte) on Dec 14, 2004 at 15:55 UTC
    Does the output file have to exist before it the system call on this code is made? Can it not create the file on the fly?

      It can fail for numerous reasons. The most common are probably:

      • Insufficient permissions
      • Path doesn't exist
      • Disk error (someone ejected it)
      • Invalid characters in file name
        I am referring to a file that is on another drive, a shared network drive. But I have done this with the input file that is used in the same system call. The file name is fine and so is the directory path. The permissions on the directory are fine.

      The correct answer is: "Try it, or read perldoc -f open". The short answer is that using ">" in your open will (attempt to) open the file, clobbering (ie removing) its contents, or creating the file anew if necessary.

      Update: added documentation pointer.

      davis
      It wasn't easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
        But my question really regards the system called statement.