The second approach is possible in a way. The best and most comfortable solution is to use a templating library. For example Text::Template or Template::Toolkit. You write up the static text and include placeholders that the library then substitutes with anything you give it

What those templating libraries do is no secret. They just put the static text into some array and fill in the placeholders *before* writing it to a file. You can do this yourself if you want, but why reinvent the libraries

But if you literally want to first store the static data into a file and then overwrite with dynamic text, you just made your live difficult for no reason. Data in a file can't be easily shifted, so either your substitutions have the same length as the placeholders (then you might work with seek to do this) or you have to designate a character as 'ignore' character and put placeholders of maximum length into the file.


In reply to Re: File dynamic write operations by jethro
in thread File dynamic write operations by perlpal

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.