Previous Table of Contents Next



My open statement keeps failing, and I'm not sure why. What's wrong?


First, check the syntax of the open statement. Make sure you're opening the right filename. Print the name before the open if you need to be sure. If you intend to write to the file, make sure you put a > in front of the filename; you need to. Most importantly, did you check the exit status of open by using open() || die "$!"; syntax? The die message might be very important in helping you find your mistake.


I'm writing to the file, but nothing seems to go into it. Where's my output going?


Are you sure that the filehandle opened properly? If you used the wrong filename, your data could be going to the wrong file. A common mistake is to open a file for writing by using backslashes in the pathname and enclosing the pathname in double quotation marks, as shown here:

open(FH, ">c:\temp\notes.txt") || die "$!";   #WRONG!

This line creates a file called c:(tab)emp(newline)otes.txtprobably not what you had in mind. Also, make sure that your open function succeeded. If you write to a filehandle that hasn't been properly opened, Perl discards the output silently un
Previous Table of Contents Next

© 2000- NIV