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


In reply to Invalid value for shared scalar -while assigning object value to array - In Threads by gjoshi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.