Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^5: Stumped with select->can_read (buffered)

by zentara (Archbishop)
on Aug 04, 2012 at 08:00 UTC ( #985394=note: print w/ replies, xml ) Need Help??

in reply to Re^4: Stumped with select->can_read (buffered)
in thread Stumped with select->can_read

Would it be horrible (performance wise) to read one byte at a time until I reach a newline character, thus forming a real $line?

It's been done before. :-) It certainly is inefficient. What I would do, is sysread as big of chunks as you can, then concat everything into a temp buffer, then split the buffer on newlines into an @array. If the scalar @array is greater than 1, then you have a line. Return the last @array element to your $temp_buffer, and process the rest of the @array elements as lines. It's called a sliding buffer, and you can google for "perl sliding buffer" for examples.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Comment on Re^5: Stumped with select->can_read (buffered)
Re^6: Stumped with select->can_read (concat)
by tye (Cardinal) on Aug 04, 2012 at 16:48 UTC
    sysread as big of chunks as you can, then concat everything into a temp buffer

    sysread can read onto the end of the buffer, avoiding the need to copy the data again:

    sysread( $fh, $buf, 16*1024, length($buf) );

    - tye        

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985394]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2015-05-30 15:06 GMT
Find Nodes?
    Voting Booth?

    In my home, the TV remote control is ...

    Results (596 votes), past polls