Nich240 has asked for the wisdom of the Perl Monks concerning the following question:
How do I pass the $_ outside the loop?
Here is my code:#!C:\strawberry\perl\bin use warnings; use strict; use Net::SSH2; use MIME::Lite; use Config::Tiny; my $ssh2 = Net::SSH2->new(); my $ipaddr="w.x.y.z"; my $username="username"; my $password="password"; $ssh2->connect("$ipaddr") || die "PROBELM - $!"; $ssh2->auth_password("$username","$password") || die "Username +/Password not right"; my $chan = $ssh2->channel(); $chan->blocking(0); $chan->exec('export NAS_DB=/nas;/nas/bin/nas_fs -list'); print "Chan= $chan\n"; my $result; while (<$chan>) { $result=$_; #Desired output. Only works inside the loop. $result='test'; #Used for testing, this works inside and outside of lo +op #print $result; #Works } print $result; #Works if $result is set, but not with a $_; print "END";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Variable outside of loop with Net::SSH
by aaron_baugher (Curate) on May 08, 2015 at 13:30 UTC | |
by Nich240 (Initiate) on May 08, 2015 at 13:40 UTC | |
by aaron_baugher (Curate) on May 08, 2015 at 13:55 UTC | |
by Athanasius (Archbishop) on May 08, 2015 at 14:32 UTC | |
by Nich240 (Initiate) on May 08, 2015 at 14:37 UTC |