in reply to Re: For loop and Sub Routines
in thread For loop and Sub Routines

Thanks for the quick reply...

As I am a bit of a newbie to this, are you suggesting.

I am on the train home so cant test this for sure...

for my $router ( @$router_data ) { my $tty; ### Create SSH Session print "\n" . "Logging into $router->{routerName}..." . " \n"; my $ssh = Net::SSH::Expect->new ( host => $router->{routerName}, password=> $pWord, user => $uName, timeout => '3', raw_pty => 1 ); ### Logon to the Router $tty = $ssh->login(); if($tty !~ /$router->{routerName}/) { die "Error: no prompt received.\n\n"; } if ( $Action eq 'status' ) { checkStatus($router->{routerName,$ssh}); } } sub checkStatus { my $routerName = $_[0]; my $ssh = $_[1]; my $test; if ($routerName eq 'asr01') { $test = $ssh->exec("show run | in hostname "); } else { $test = $ssh->exec("show clock"); } print $test; }

Replies are listed 'Best First'.
Re^3: For loop and Sub Routines
by NetWallah (Canon) on Jul 05, 2013 at 05:17 UTC
    The call should read:
    checkStatus($router->{routerName}, $ssh);
    ALso, it is more common (and lazier, and more idiomatic) to code the passed parameters this way:
    sub checkStatus { my ($routerName, $ssh) = @_; ...
    This allows you to add parameters easily, and makes parameter positions visually identifiable without having to examine indexes.

                 My goal ... to kill off the slow brain cells that are holding me back from synergizing my knowledge of vertically integrated mobile platforms in local cloud-based content management system datafication.