in reply to Re^3: Global variables and SimpleHTTP request handler
in thread Global variables and SimpleHTTP request handler

Thank you so much, Thread::Queue does exactly what I need, though the MCE suggestion looks like it would have also worked.

There was a slight oddity that it did not work with SimpleHTTP backgrounded. I had to create my own thread for that and use run().

use threads; use Thread::Queue; my $command_queue=Thread::Queue->new(); sub handle_request { my ($self, $cgi) = @_; my $cmd_out; ........ $command_queue->enqueue($cmd_out); my $commands_left=$command_queue->pending(); myDebug("Threads - there are $commands_left items in the queue"); } my $server_thread=threads->create( sub { # Run server but do not background it. myDebug("Starting web server\n"); my $pid = MyServer->new($PORT)->run(); } } while($quit==0) { my $commands_left=$command_queue->pending(); myDebug("Queue runner - There are $commands_left entries in the qu +eue"); if($commands_left>0) { print "We have commands to process\n"; $send_command=$command_queue->dequeue(); print "Sending: $send_command\n"; } # Sleep so we do not hog the processor sleep(1); }

All seems to work nicely. :)