in reply to begining of a file
One way is to put the contents of the file into an array, write your first line(s), then spit the array afterward. Example (yeah I'm skipping strict, warnings, errorcodes, and other good programming practices):
open (GB,"$bookfile"); @oldstuff = <GB>; close GB; open (FILE,">$newfile"); print FILE "pre-pendings here\n"; print FILE "@oldstuff"; close FILE; # rename file if necessary
Another way is to write your pre-pending content to a file, then stream (is this the right word) the old file contents. In other words:
open (FILE,">$newfile"); print FILE "pre-pendings here\n"; open (GB,"$bookfile"); while (<GB>) { print FILE "$_"; } close GB; close FILE; # rename file if necessary
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: begining of a file
by clintp (Curate) on Aug 21, 2001 at 19:11 UTC |