[Gllug] perl question

Alain Williams addw at phcomp.co.uk
Mon Mar 5 09:53:30 UTC 2007


On Mon, Mar 05, 2007 at 09:45:59AM +0000, Jack Bertram wrote:
> I have a little perl script which uses ncurses to display a list of
> mailboxes, checks new mail, allows me to run various commands and so on.
> It works perfectly, but - essentially because the main body of the
> program is an infinite loop which checks for keypresses and for mailbox
> updates - uses 50% of my CPU time.  No problem on my main machine but a
> bit of a pain for the little arm box that I'm going to migrate to.
> 
> Anyone know if there is a canonical way of writing the main loop to stop
> this happening in perl?  I only need to poll the mailboxes once every
> few seconds, but I need to respond to keypresses instantly, so a sleep()
> call won't work.

Use 'select', you specify masks for the fileds that you are interested in
(read, write & error) and a timeout as 4th argument.

Beware: perl has 2 forms of select, you want the one that takes 4 arguments.

-- 
Alain Williams
Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list