Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Answer: How do you write to the middle of a file?

by Anonymous Monk
on Feb 11, 2000 at 23:06 UTC ( #3402=categorized answer: print w/replies, xml ) Need Help??

Q&A > files > How do you write to the middle of a file? - Answer contributed by Anonymous Monk

Such is the evil of the standard (read UNIX) file model. One solution is as follows:
$flen = -s $file; # file length in bytes $from = 42; # insertion point open FILE, '+<the/file.ext' or die "Couldn't open file: $!"; read FILE, $buf, ($flen - $from), $from; seek FILE, $from, 0; print FILE 'blahblahblah', $buf;

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2020-04-03 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (30 votes). Check out past polls.

    Notices?