Well, there's really no way to write to the beginning of a file without
pushing the rest of the contents back.  If you had been successfull with
your seek attempt, you would have overwritten the beginning of the file.
Probably your best bet would be to create a temp file like this:

open(TEMP,">tempfile.txt");
print TEMP @myFileHeader;   #start with your own text
open(ORIG,"originalfile.txt");
while(<ORIG>){
   print TEMP $_;           #append the contents of the original file
}
close TEMP;
close ORIG;

Then you can rename the file to the original filename.

-----Original Message-----
From: Troy May
To: Perl Beginners
Sent: 3/9/02 11:36 PM
Subject: Writing to beginning of file

Hello,

How do you write to the beginning of a file?  I see only 3 options to
open a
file:  to read, to overwrite, and to append to the end of the file.

I tried seeking to the beginning before the write, but it doesn't work.
Seek must only work for a read.

Any ideas?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to