Reputation: 421
I am new to perl, and I was trying to get a tcp server that listen on a specific port for data transfer. In almost every tutorial, I could see
use IO::Socket::INET
# flush after every write
$| = 1;
but I cannot identify the use case of this. The code works without this chunk as well. Can someone please point out why this is needed, and why is this used as a best practice?
Upvotes: 1
Views: 503
Reputation: 3165
Setting $| to a non-zero value forces a flush after every write. If the output is not to STDOUT, it would be block buffered, and since you are writing to a socket, this is set to a non-zero because you can see in realtime, the output. If it is set to zero and you write to a socket, there would be a delay/latency, because of the block buffering.
Upvotes: 4