Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

Re: FreeBSD reading/writing workaround?

by hdp (Beadle)
on Apr 25, 2001 at 08:16 UTC ( [id://75376] : note . print w/replies, xml ) Need Help??

in reply to FreeBSD reading/writing workaround?

I just tested open using "+<file" syntax, and it worked for me. This is FreeBSD 4.2-STABLE on i386, perl 5.005_3. I suggest giving similar details about your configuration -- maybe someone's heard of similar problems (though to be honest I suspect the error is in your code, not in the OS or perl). Showing some code that doesn't do what you'd expect would help a lot as well.

As an aside, I'm assuming that you're using the "different instances" you refer to because you are having problems with open. If not (i.e. if you're going to be using multiple instances regardless of whether open behaves or not), have you looked at flock? (If you use flock, keep in mind that its locks are only advisory, so a completely different process can just clobber it.)


Replies are listed 'Best First'.
Re: Re: FreeBSD reading/writing workaround?
by Anonymous Monk on Apr 26, 2001 at 08:17 UTC
    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?
      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.