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.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.
Thanks,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 }
In reply to Problems Using Local by Dru
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |