> -----Original Message----- > From: Jochen Stenzel [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 02, 2004 3:06 AM > To: Brian Michalk > Cc: Rocco Caputo; [EMAIL PROTECTED] > Subject: Re: New Guy Questions > > > > Hello, Brian, > > BM> while ($$data =~ s/^(.*?\n)//) { > $self->>process_command($1); > BM> } > > BM> That little regex in there is killing my performance. If one > uses select, > BM> one must expect to read partial or multiple lines. That > means that one must > BM> search for line terminators, and that is precisely what I am > trying to get > BM> around without having to resort to threads or forking. > > BM> Of course I know regexes are evil, index() is much better in > performance, > BM> but it still doesn't solve what I am truly after, and that is > a select() > BM> that returns when a complete line of data is available, not just a few > BM> characters. > > would it be possible for you to switch to a stream protocol? In that > case, you could read blocks of data, knowing their length before, > using fast sysread() or read() calls, without need to investigate the > data by a regular expression. > > Such protocols are available in CPAN. POE, for example, has them (I > only read about them, but I think the block IO wheels would do this). > Or have a look at IPC::LDT, which implements such a protocol directly > and handles data transparently, so you could send everything including > your terminator and expect to receive it as one block on the other > side (the block length is determined dynamically). It can be used with > Event. > > Jochen
This is getting closer. I have tried to switch stream protocols on the serials ports to make it line oriented. However, the instant I execute fcntl() to make the file descriptor nonblocking, I think it communicates back to the serial driver and issues an ioctl() that undoes the line buffering. I have stumbled across the event wheel, and will read it with more interest. Brian Michalk <http://www.michalk.com> Life is what you make of it ... never wish you had done something. Aviator, experimental aircraft builder, motorcyclist, SCUBA diver musician, home-brewer, entrepreneur and barely single