Right, I'm gonna tell you something you already know, and in fact, already expect and possibly even dread: (all together now) there's more than one way to skin a camel (forgive me the gratuitous rephrasing :) ). In your case, here are some ways of doing this:

* 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:

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";
* 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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.