user786 has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use autodie; use Net::SSH::Expect; # ssh into a router my $ssh = Net::SSH::Expect->new( host => "ipaddr", password => 'user', user => 'pwd', raw_pty => 1, ); my $login_output = $ssh->login(); # execute the commands $ssh->exec("command 1"); $ssh->exec("command 2"); # open a file and read the config information open my $prep, '<', 'config.txt; while (my $config = <$prep>) { chomp $config; my $conf = $ssh->exec("$config"); print("$conf"); }
the above code works and provides the required output. However i would like to convert this code into a function so that i can reuse this for various config files.
For instance: If I make the following function call config_function("config2.txt"); The script should read that 2nd config file and execute the commands.Is it possible to do that.? suggestions please.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl : Convert a monolithic code to a function
by 1s44c (Scribe) on Jun 28, 2014 at 23:26 UTC | |
by user786 (Sexton) on Jun 29, 2014 at 00:58 UTC | |
by Anonymous Monk on Jun 29, 2014 at 01:09 UTC | |
by user786 (Sexton) on Jun 28, 2014 at 23:47 UTC |