in reply to Re: FreeBSD reading/writing workaround?
in thread FreeBSD reading/writing workaround?

I'm on perl, version 5.005_03 built for i386-freebsd...the code is as follows:
open(FH,"+<./file.dat") || die("Can't open ./file.dat for reading/writ +ing: $!"); flock(FH,LOCK_EX); seek(FH,0,0); @dat = <FH>; foreach (@dat) {chomp} # this is where I process @dat, and when I feed text # manually into it, it works. the problem doesn't # lie in this segment of the code seek(FH,0,0); print FH join("\n",@dat); flock(FH,LOCK_UN); close(FH);
Now, i can open the file for reading, and i can open it for writing, and both work fine. But when I try reading AND writing, it doesnt spring an error, it simply doesnt read anything from or write anything to the file. Should I try +>instead of +<or what?

Replies are listed 'Best First'.
Re: Re: Re: FreeBSD reading/writing workaround?
by hdp (Beadle) on Apr 26, 2001 at 08:39 UTC
    I've taken your code and run it unchanged on my machine except for the addition of this line (push @dat, $dat[rand(@dat)]) just before the second seek. It does what I'd expect it to, reading in the file and writing it out again with a random line from the file appended.

    I suggest you show the rest of your code, even though you don't think the problem lies there.

    hdp.