Can someone tell me why Perl is not letting me use local here? This is the error I'm getting:
Global symbol "$stout" requires explicit package name at ./temp.pl line 48. Global symbol "$stout" requires explicit package name at ./temp.pl line 49. Global symbol "$stout" requires explicit package name at ./temp.pl line 71. Global symbol "$stout" requires explicit package name at ./temp.pl line 75. Execution of ./temp.pl aborted due to compilation errors.
From everything I read, I thought I could declare $stout as a local variable so that it can also be used in the run subroutine. I tried to make it global declaring it with my outside of the the subs, but I got some strange results. I'm trying to figure out what code ssh returns on a successfull connection.
45 sub connect { 46 47 for(@host){ 48 local $stout = run($_); 49 unless($stout == 256) { 50 $success++; 51 last; 52 } 53 print "$_ not responding\n"; 54 } 55 print "All hosts not responding" unless $success; 56 57 } 58 59 60 # 61 62 sub run { 63 64 my $host = $_[0]; 65 my $user = 'root'; 66 my $cmd = '/usr/local/scripts/temp.sh'; 67 68 ssh("$user\@$host", $cmd); 69 70 71 if($stout == 256) { 72 print "Problem sshing: $!\n" and exit; 73 } 74 else{ 75 print "STDOUT is: $stout\n"; 76 }
Thanks,
Dru

In reply to Problems Using Local by Dru

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.