for example
#say this is my news file
blah
#and i just posted to it, i want it to do this
new post
blah
how do i do this? please tell me if i need to include a little more info
Something like this seems pretty close:
open (OLD, $oldfile) or die "Cant open $oldfile: $!"
open (NEW, ">", $oldfile . "~") or die "Cant open new file: $!"
while (<OLD>) {
print NEW;
if ( /#new stuff goes after this comment/ ) {
print NEW, $newstuff;
}
}
close OLD;
close NEW;
rename $oldfile . "~", $oldfile or die "Cant rename file: $!";
open(FIRSTRUN,"$myfile");
@vn=<FIRSTRUN>;
close (FIRSTRUN);
####
$message= "$mymessage";
$message=~ s/\n/<br>/g;
####
open(OVERWRITE,"$myfile");
print OVERWRITE qq~$message @vn~;
close (OVERWRITE);
Thanks for the quick responses!
:)
Instead:
Open the file (without clobbering it)
lock it
read it
seek back to beginning
write new data
write what you read above
close file (will automatically unlock).
But I should also mention that the reversing idea from above would be faster as long as the file isn't going to be getting too big.