On Sat, Mar 09, 2002 at 11:36:08PM -0800, Troy May wrote:
> How do you write to the beginning of a file?
That's an easy one: Just turn the file around, and append to its end.
# cat > regular
first
second
third
^D
# mkfifo backwards
# while : ; do tac regular > backwards; done &
[1] 18464
# cat b
Troy May [[EMAIL PROTECTED]] quoth:
*>Hello,
*>
*>How do you write to the beginning of a file? I see only 3 options to open a
*>file: to read, to overwrite, and to append to the end of the file.
*>
*>I tried seeking to the beginning before the write, but it doesn't work.
*>Seek must only work fo
Troy May wrote:
>
> Hello,
Hello,
> How do you write to the beginning of a file? I see only 3 options to open a
> file: to read, to overwrite, and to append to the end of the file.
>
> I tried seeking to the beginning before the write, but it doesn't work.
> Seek must only work for a read.
>
Troy May wrote:
>
> Hello,
>
> How do you write to the beginning of a file? I see only 3 options to open a
> file: to read, to overwrite, and to append to the end of the file.
>
If you think about the file as an array with one char on each index:
my @string = split (/|/, "this is a test");
n
Well, there's really no way to write to the beginning of a file without
pushing the rest of the contents back. If you had been successfull with
your seek attempt, you would have overwritten the beginning of the file.
Probably your best bet would be to create a temp file like this:
open(TEMP,">