Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

knowing when file is created 2

Status
Not open for further replies.

math

Programmer
Mar 21, 2001
56
BE
hi,

If you open a file to write:
Code:
open(FILE, ">file.txt");
...
then perl will create the file if it doesn't exist... but what I want to know is how I find out whether the file needed to be created...

The reason why is that is the file is just created I would like to put something standard in the file... a default-txt... that gets edited during my program... So to put a standard something in a file, I need to know whether the file needed to be created... and just making the file and editing it manually isn't an option cause the filename is dynamic... (generated by the current date)

Can anyone help?
Thanx in advance,
math
 
after you open it, do this test:[tt]
if (-s FILEHANDLE > 0) {}[/tt]

that will only be true if the file already had data in it. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 

Also if (-e "file.txt"){} would return true if it exists, but would also return true if it was empty and existed.

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top