* Way the first: read in your target file one line at a time, write it back out to a temporary file but add your new content when necessary:
* Way the second: play seek games. This is probably the easiest if you want to enter your text at a fixed position in the file. I'm pressed for time at the moment, so I'll leave the implementation of this as an exercise to the reader. The link above should get you almost the entire way there.use strict; my $newcontent="My camel has been bitten by a rather large flea. Pleas +e call a vet."; my $input="camel.cgi"; my $tempfile="/tmp/camel.$$"; open TARGET, "<$input" or die "Blerch: $!\n"; open TEMP, ">/$tempfile" or die "Hcerlb: $!\n"; while (<INPUT>) { # check for your cue: could be a running counter to # keep track of lines read, could be a regexp, could # be just about anything else. Let's assume the check # sets $ship_ahoy when you need to add lines. if $ship_ahoy {print TEMP $newcontent} print TEMP; } close INPUT; close TMP; rename $tempfile $input or die "Hrlecb:$!\n"; print "Beware, this is untested code, and could definitely do with mor +e robust error checking!\n";
CU
Robartes-
In reply to Re: Doing a "Print" to a predetermined location in another file
by robartes
in thread Doing a "Print" to a predetermined location in another file
by Donnie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |