user786 has asked for the wisdom of the Perl Monks concerning the following question:
I have written a function in perl (Thanks to perl monk) The below script works as expected and provides the desired output. I have been learning about functions and making function calls. I'm trying to make a function call by assigning it to a variable.
Now I tried making the function call my assigning it to a variable $p and that should throw an error if some thing goes wrong in the function. This is what i tried .use strict; use Carp; use warnings; use autodie; use feature qw/say/; use Net::SSH::Expect; print "\n[INFO] script Execution Started\n"; #-- ssh into a router my $ssh = Net::SSH::Expect->new( host => "ip addr", password => 'password', user => 'user name', raw_pty => 1, ); my $login_output = $ssh->login(); #--Function to read config file and execute the commands on the rout +er accordingly. sub mysub { my ($ssh,$filename) = @_; $ssh->exec("cmd 1"); $ssh->exec("cmd 2"); open my $p, '<', $filename; while (my $config = <$p>) { chomp $config; my $conf = $ssh->exec("$config"); print("$conf"); } } #--> Function call. mysub($ssh,"file name.txt");
my $p = mysub($ssh," file name.txt "); if ($p) { print {*STDERR} "Something went wrong [$p]." or carp 'Could not print error about the config file'; return 0; }
However this is not working. Any suggestions ?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl function calls.
by toolic (Bishop) on Jul 07, 2014 at 14:50 UTC | |
Re: Perl function calls.
by hardburn (Abbot) on Jul 07, 2014 at 14:53 UTC | |
by user786 (Sexton) on Jul 07, 2014 at 15:05 UTC | |
by hardburn (Abbot) on Jul 07, 2014 at 17:34 UTC | |
Re: Perl function calls.
by BillKSmith (Monsignor) on Jul 07, 2014 at 15:53 UTC | |
by user786 (Sexton) on Jul 07, 2014 at 16:05 UTC | |
by Anonymous Monk on Jul 07, 2014 at 16:30 UTC | |
Re: Perl function calls.
by perlfan (Parson) on Jul 07, 2014 at 15:47 UTC |