CGI Development

Moderators: Jonathan
Number of threads: 57
Number of posts: 124

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: Append to a file (from the beginning). Posted by rinmak on 7 Feb 2002 at 5:32 AM
hey,

there is an eaier way to do it, but DrGonzos way is a safer way, anyway the easy way is to read the whole file into a scalar, add what u want to the end and then write it out again, eg:

open(INFILE,"data.txt") || die;
while(<INFILE>) { $buffer .= $_; }
close(INFILE);

$buffer = "Put here what you want at the start\n" . $buffer;

open(OUTFILE,">data.txt") || die;
print OUTFILE $buffer;
close(OUTFILE);


sorry im on windoze at the moment so i cant test the code but it all looks right, just make sure that you use DrGonzos method when the file starts getting into the megabytes range :)
Thread Tree
InFeStEd Append to a file (from the beginning). on 10 Dec 2001 at 2:22 PM
DrGonzo Re: Append to a file (from the beginning). on 21 Dec 2001 at 12:35 AM
rinmak Re: Append to a file (from the beginning). on 7 Feb 2002 at 5:32 AM
helihopper Re: Append to a file (from the beginning). on 13 Jan 2009 at 5:35 PM
helihopper Re: Append to a file (from the beginning). on 13 Jan 2009 at 5:35 PM
superjoe30 Re: Append to a file (from the beginning). on 19 Sept 2002 at 2:43 PM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.