Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: insert into beginning of file

by fsn (Friar)
on Jul 22, 2002 at 15:07 UTC ( #184089=note: print w/replies, xml ) Need Help??


in reply to insert into beginning of file

Tie::File is of course the way to do it. The old, hardcore, quickhack, low memory, no extra module, the-way-they-used-to-do-it-in-the-80's way is:

#!/usr/bin/perl open INFILE, "<infile"; open OUTFILE, ">tmpfile"; # Create your temporary names with care, +or die a painful race-condition death. print OUTFILE qq!Here you print the new stuff. ... !; while (<INFILE>) { print OUTFILE $_; } close INFILE; close OUTFILE;

and then rename the tempfile.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://184089]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2022-11-26 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?