in reply to How to split rows coming from the database

If you want to keep $content as small as possible, you need to do both, splitting and keeping the remainder:

... my $remainder = ''; while (1) { my $buf; my $n = $self->_get_socket()->read_entity_body($buf, 1024); $buf = $remainder . $buf; $remainder = ''; die "can't read response: $!" unless defined $n; last unless $n; if( $buf =~ s!([^\n]+\z)!! ) { $remainder = $1; }; push @response, split (/\n/, $buf); }

You need to keep the incomplete line around until the next newline is read.

Replies are listed 'Best First'.
Re^2: How to split rows coming from the database
by mocnii (Acolyte) on Nov 08, 2016 at 14:37 UTC

      First of all, thanks for correlating this bug and for reporting a fix!

      I'm not really sure your fix is complete, because I think it will lose the contents of $remainder if read_entity_body returns an empty string but $remainder still has content. It should at least warn or signal an error.