At first:
do not use echo in perl script. This is unpleasant when you get excellent I / O routines.
using cat to read files is about as unpleasant as using echoes.
Reading <STDIN> similar to a blocking call, which means your script will stop.
but itβs not as bad as it seems, because otherwise you start a busy wait loop that repeats the cat file. This is a very bad idea.
You assume that writing such a file is an atomic operation when it is not. You will also encounter problems with this.
What I suggest you do is take a look at IO::Handle and also consider using flock to make sure the file is locked for I / O. You might want to consider File::Tail .
I would suggest, however, that you want to consider a different IPC mode - since file sharing is rather inefficient. If you really want to use the file system for your I / O, you may need to use the FIFO channel - each client must open its own, and the server will read and combine them.
In any case, you will either need to use IO::Select , or perhaps multithreading, just to swap between reading and writing. http://perldoc.perl.org/IO/Select.html
source share