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:
and then rename the tempfile.
#!/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.
|
---|
In Section
Seekers of Perl Wisdom