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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you write to only part of a file?

Status
Not open for further replies.

cradletoenslave

Programmer
Jan 28, 2005
29
0
0
US
I'm having trouble appending only part of a file. So far, I've gotten the feel of appending files and writing to them, but I can't get it to write to only part of a file. For example:

<html>
<body>
insert information here
</body>
</html>

What kind of a script can do that? When appending, it will only add on to a file. Is there a way to put information in just the middle of a file?
 
if it's a simple as that
print FH "<html>\n<body>\n$stuff\n</body>\n</html>";

How big are the files, and can you specify what exact breaks you want to break on?
Code:
$/=1;
$file=<FH>;
close FH;
$start  =~ /^(.?)<body>/;   #not sure
$finish =~ /</body>(.?)/;   #not sure
open FH2 ">newfile.htm";
print FH2 "$start<body>$stuff</body>$finish";
[/code]

I'm not sure about the regexes, but it should give you a few pointers

HTH
--Paul

cigless ...
 
It's a little more complicated than that. I know how to put the information on the next file, but I don't know how to put it in the middle of the file. What I'm doing is making a basic guestbook script. Yes, I know you can find them already made, but I want to do this one myself. I don't want to just print the HTML, I want the script to find the spot where it's supposed to print the information. Doing it the method you posted earlier would only resubmit all of the starting and ending tags to the HTML page.

Thanks for the help.
 
cradle said:
I want the script to find the spot where it's supposed to print the information.

See spot, define spot

--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top