gjoshi has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

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

  • Comment on Invalid value for shared scalar -while assigning object value to array - In Threads
  • Download Code

Replies are listed 'Best First'.
Re: Invalid value for shared scalar -while assigning object value to array - In Threads
by AppleFritter (Vicar) on Oct 16, 2015 at 09:35 UTC
      I looked at it but I did not get it how to do that. that's why I have asked this question. If anyone has example then it would be useful for me. thanks --girija
        Try shared_clone
Re: Invalid value for shared scalar -while assigning object value to array - In Threads
by BrowserUk (Patriarch) on Oct 16, 2015 at 14:48 UTC

    Please see Re: How do you share an object(Telnet Session) between threads? for the explanation for why sharing a telnet session between threads is a bad design and will never work. Also, how to avoid the problem.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Invalid value for shared scalar -while assigning object value to array - In Threads
by Anonymous Monk on Oct 16, 2015 at 10:18 UTC

    Where for each targets I am doing telnet and returning telnet handle and storing it in the global array.

    Why are you storing the handle in the global array, what do you hope to accomplish ?

      its a legacy program and need that global var :)

        its a legacy program and need that global var :)

        :) but it doesn't work :D