P:\test>369260
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
1 : 1
2 : 1
3 : 1
4 : 1
7 : 1
6 : 1
5 : 1
8 : 1
9 : 1
10 : 1
Use of uninitialized value in join or string at P:\test\369260.pl line 16.
4 : 2
...
####
P:\test>369260
1 : 1
2 : 1
3 : 1
1 : 2
4 : 1
5 : 1
6 : 1
7 : 1
8 : 1
9 : 1
10 : 1
1 : 3
...
####
### THIS IS PSEUDO CODE ONLY. IT WILL NOT RUN. IT WILL REQUIRE MUCH WORK.
#! perl -w
use strict;
use threads;
use threads::shared;
use Thread::Queue;
our $TELNETS = 10;
## Pre-create the queues that will be tied.
our @queues : shared = map{ Threads::Queue->new } 1 .. $TELNETS;
my $done : shared = 0;
sub telnet{
my( $Qno ) = @_;
require Net::Telnet;
require Tie::Glob::Queue;
open REALFILE, '>>', "LOGS/telnet.$Qno" or die $!;
## Pass in the Q handle for this tied handleQ
tie *LOG, 'Tie::Glob::Queue', \$queue[ $Qno ];
my $telnet = Net::Telnet->new( ..., log_to => \*LOG, ... );
...
return;
}
## Start the threads, pass the Q nos. ( 1 .. 10 maps to 0 .. 9 etc.)
my @threads = map{ threads->new{ \&telnet, $_ -1 }-detach } 1 .. $TELNETS;
## Require (NOT use) the Tk stuff AFTER creating the threads.
require Tk;
...
sub update {
my( $Qno, *LOGFILE ) = @_;
while( !$done ) {
## Each time we are called, read the new data from the queue
while( my $logdata = $queues[ $Qno ]->dequeue ) {
## And add it to the window
$listbox->adddata( $logdata );
## and the logfile
print LOGFILE $logdata;
}
}
}
my $main = Tk->new(...);
my @loggers = map{
$main->ListBox(
update_callback => [
\&update,
Qno => $_,
LOGFILE = *LOGFILE
]
)
} 1 .. $TELNETS;
## run the program
MainLoop;