in reply to Re^2: Elegant Way of Inserting Text at the Start of the File
in thread Elegant Way of Inserting Text at the Start of the File
You can use '+<' to open the file for read and write without truncating. Then seek does work and the print overwrites the beginning of the file.
$ echo -ne "foo\nbar\n" > file $ cat file foo bar $ perl -le'open my $fh, "+<", "file" or die $!; seek $fh, 0, 0 or die +$!; print $fh "bazz";' $ cat file bazz ar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Elegant Way of Inserting Text at the Start of the File
by ikegami (Patriarch) on Nov 19, 2008 at 04:24 UTC |