in reply to Re^3: exiting a subroutine neatly (Throwable)
in thread exiting a subroutine neatly
use Guard qw(scope_guard); sub ssh_execute_and_check { my $ssh = shift; my ($ret, $err) = $ssh->execute(@_); if ( $err or $ret =~ /Unknown command:/m ) { MyErr->throw({err => $err, ret => $ret, args => [@_]}); } return $ret; } sub foo { $ssh->start_session($ssh_host) or MyErr->throw(...); scope_guard { $ssh->exit_session; $ssh->close_session; }; my $ret1 = ssh_execute_and_check($ssh, 'command1', 'expect1'); my $ret2 = ssh_execute_and_check($ssh, 'command2', 'expect2'); ... 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: exiting a subroutine neatly (Throwable)
by Anonymous Monk on May 05, 2015 at 11:08 UTC | |
by salva (Canon) on May 05, 2015 at 11:28 UTC | |
by Anonymous Monk on May 05, 2015 at 16:43 UTC |