I am using threads. Where for each targets I am doing telnet and returning telnet handle and storing it in the global array.
While storing it in the Array I am getting error as: Invalid value for shared scalar. code is as below.
our @TelnetHandler = (); share(@TelnetHandler); print "\n"; foreach my $TempUENum (@UEListAll) { my $telhost = "ue$TempUENum-rig619"; print "HOST: $telhost \n"; my $t = threads->new(\&ConnectToTelnet,$TempUENum,"$telhost",5,'#' +,1,"return"); 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)= @_; 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] = "UE$ue"; $TelnetHandler[$ue] = $t_send; # GETTING ERROR HERE } return $ue; }
Anyone could you please tell me what do I have to do store t_send value in the @TelnetHandler array?
Thanks --girija
In reply to Invalid value for shared scalar -while assigning object value to array - In Threads by gjoshi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |