QA

 <  Day Day Up  >  

Q&A

Q1:

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

A1:

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.

Q2:

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

A2:

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.txt ”probably 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

 <  Day Day Up  >  


SAMS Teach Yourself Perl in 24 Hours
Sams Teach Yourself Perl in 24 Hours (3rd Edition)
ISBN: 0672327937
EAN: 2147483647
Year: 2005
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net