in reply to subroutine For ssh

Hi

TNX for all comments

it was ok with this type

sub SSHApp { my ($MyIP , $MyUser , $MyPass , $MyPass2 , $command ) = @_ ; #SSH Connection to Applaince my $ssh_1 = Net::Appliance::Session->new({personality => 'ios', tr +ansport => 'SSH', host => "$MyIP",}) ; $ssh_1->connect({ username => "$MyUser", password => "$MyPass" + }) ; $ssh_1->begin_privileged({ password => "$MyPass2"}) ; print $ssh_1->cmd("$command") ; $ssh_1->end_privileged ; $ssh_1->close; }

Replies are listed 'Best First'.
Re^2: subroutine For ssh
by Fletch (Bishop) on Oct 09, 2019 at 13:34 UTC

    Couple of style nits:

    It's not necessary to requote everything as you've done in several places (e.g. "$MyUser" or "$command"). It's extra, unneeded visual noise and (in weird corner cases) could trigger behavior you don't intend (quoting something which has stringification overloaded; alternately if down the road the underlying API expects a HASHREF for an argument where it used to expect a SCALAR you've now got to go through and remove them).

    And more of a personal preference but WRT your variable naming, the "My" prefix on everything doesn't really gain you anything. Were you to keep it it's more common to use lowercase underscore delimited local lexical variable names rather than CamelCase (e.g. $unprivileged_password or $privileged_password might be better than $MyPass and $MyPass2).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.