That might depend on the operating system (at least I think that some old OSes with structured files types could behave totally different from Unix/Win).

General remark: it is good idea to state the OS and Perl version (including used modules) if you ask a question.

If you are using some sort of Unix, the answer is: no. You can seek any position inside the file, but if you write, you overwrite.

Now, the question is, what do you want to do? If you generate some output (say, dynamic HTML) you might just buffer it into variables and write it out in one go. If your intermediate results have to be persistent (i.e. written to disk), you might consider storing them in seperate files and build your final file as needed. (Might be a good idea anyway, 'cause you don't manipulate earlier results which makes debugging easier.) If that is no option, too, I'm afraid you got to go with the tmp-file solution proposed by the other monks.

Hope that helps a bit ...

Andreas

UPDATE:Merlyn pointed to the faq section on this topic when answering a similar question. I looked it up and there is a description on how to do it with temporary files: look here. Aaah, resourceful monastry ;-))


In reply to (atl) RE: Inserting stuff into a filehandle. by atl
in thread Inserting stuff into a filehandle. by Punto

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.