gjoshi has asked for the wisdom of the Perl Monks concerning the following question:
I am creating different telnet handles in a loop in diff threads and I want to store that handle in global array. I want to telnet to multiple targets simultaneously.
I am modifying legacy program so I need that global array with all telnet handles.
#!/usr/local/bin/perl -w use warnings; use threads; use threads::shared; use Net::Telnet; my (@TelnetHandler) :shared; my @UEListAll = (); my @threads; $RigNumber = "619"; my $i = 1; for ($i=1; $i <= 5; $i++) { my $retVal = `host ue$i-rig$RigNumber`; if($retVal =~ /not found/) { print "UE NOT CONNECTED \n"; } else { push(@UEListAll, $i); } } print "ARRAY : @UEListAll \n"; foreach my $TempUENum (@UEListAll) { my $telhost = "ue$TempUENum-rig619"; print "HOST: $telhost \n"; my $t = threads->new(\&ConnectToTelnet,$TempUENum,"$telhost",5,'#' +,1,"return", \@TelnetHandler); push(@threads,$t); } foreach (@threads) { my $num = $_->join; print "done with $num\n"; } print "\n****** THREAD ******** \n"; foreach my $tmp (@TelnetHandler) { print "Main TelNet Handle: $tmp \n"; } print "End of main program\n"; sub ConnectToTelnet { my ($ue, $host, $timeout, $prompt, $telnetmode, $errmode, $Ary_ref) += @_; print "Connecting to UE$ue: $host \n"; my $tid = threads->tid(); print "\nStarting Thread: $tid \n"; my $t_send = new Net::Telnet ( Host => $host, Timeout => $timeout, Prompt => '/'.$prompt.'$/', Errmode => $errmode, Telnetmode => $telnetmode ); if(!defined(t_send)) { print "Can't Telnet to UE \n"; } else { print "TELNET HANDLE UE$ue: $t_send \n"; $TelnetHandler[$ue] = \$t_send; push (@TelnetHandler, \$t_send); } }
I am getting an error run time error where I am trying to store value in an array. Please help me. thanks --girija
|
|---|