Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

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


in reply to How do you write to the middle of a file?

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
Node Status?
node history
Node Type: note [id://3402]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2021-05-09 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (100 votes). Check out past polls.

    Notices?