Koelling
I Think Different
Hello all,
I'm trying to write a program, actually a pair of programs in perl. The first program should accept a commandline argument and write it to a file. The second program should loop over the lines in that file and process each one in turn, then delete it. It's your typical queue setup.
I'm trying to figure out how I can remove the entry from the file once it's been processed. I don't want to miss any commands from the enqueue program so I need to have a lock on the file. When I open the file as read/write (+<) on the deque program, I can't delete the first line since it seems to append to the file. What I'd like to do is open the file as read only (or readwrite, doesn't matter), process the line and save the remainder of the file to an array, then open it again for writing since that will clear the whole file and write out the array. The only problem with this is closing the file will release the lock and my enque program could write to the file!
I know there's some smart people here, I hope you will find my problem entertaining (or else you have already seen the answer.) Thanks everyone! Alternate solutions welcomed as well.
I'm trying to write a program, actually a pair of programs in perl. The first program should accept a commandline argument and write it to a file. The second program should loop over the lines in that file and process each one in turn, then delete it. It's your typical queue setup.
I'm trying to figure out how I can remove the entry from the file once it's been processed. I don't want to miss any commands from the enqueue program so I need to have a lock on the file. When I open the file as read/write (+<) on the deque program, I can't delete the first line since it seems to append to the file. What I'd like to do is open the file as read only (or readwrite, doesn't matter), process the line and save the remainder of the file to an array, then open it again for writing since that will clear the whole file and write out the array. The only problem with this is closing the file will release the lock and my enque program could write to the file!
I know there's some smart people here, I hope you will find my problem entertaining (or else you have already seen the answer.) Thanks everyone! Alternate solutions welcomed as well.