Gossamer Forum
Home : General : Perl Programming :

How to write to a file

Quote Reply
How to write to a file
I know how to open a file and write to it(I think), but how do you make it write to a certain area of the file like a form field?

------------------
Patrick Chukwura
http://nytesoft.hypermart.net
Quote Reply
Re: How to write to a file In reply to
can anyone answer my question?

------------------
Patrick Chukwura
http://nytesoft.hypermart.net
Quote Reply
Re: How to write to a file In reply to
How would I do it with a mailing list? I want it to save the subscribers email to a file and allow me to send email to all of them.

------------------
Patrick Chukwura
http://nytesoft.hypermart.net
Quote Reply
Re: How to write to a file In reply to
 
Quote:
how do you make it write to a certain area of the file like a form field?

I don't think you can do that with perl, at least, not directly. What you would need to do is read in the file and write it back out to another file, up to the point where you want to add the new data. Then, write out the new data and, finally, read in the rest of the file and write it out to the other file. Then, when the files are closed, delete the original and rename the other file to what the original was.

Anyway, that is how I would do it but, like I said, there may be another way.
Quote Reply
Re: How to write to a file In reply to
Let's assume you have a file to contain email addresses located on the following path:

Code:
(-e $emailfile) ?
open (SUBS, ">>$emailfile") : # Append
open (SUBS, ">$emailfile"); # Create

Then using:

Quote:
print SUBS "$emailaddr\n";

will always write the new email address to the end of the file, each on a separate line.

This is pretty simplified and doesn't contain any error checking for the file open statement or other things you may need. But it does give you a starting point.

[This message has been edited by Bobsie (edited April 04, 1999).]
Quote Reply
Re: How to write to a file In reply to
OK thanx I will try it

------------------
Patrick Chukwura
http://nytesoft.hypermart.net