http://www.perlmonks.org?node_id=235105


in reply to socket periodically loses data

here's the code in question... Maybe there's a more effecient way, but I think this aughta work...

$buf=''; if($fh->sysread($buf,10240)>0) { $this=$Con{$fh}; $buf=$this->{_}.$buf; while($buf=~/(.*\n)/g) { ${$Con{$fh}}{getline}($fh,$1); last unless $Con{$fh}; # it's possible that the connection can b +e deleted while there's still something in the buffer } if($Con{$fh}) { ($this->{_})=$buf=~/([^\n\r]*)$/s; if(length($this->{_}) > 10000) { ${$Con{$fh}}{getline}($fh,$this->{_}); ($this->{_})=''; } } } else { done($fh); }