in reply to Re: exiting a subroutine neatly
in thread exiting a subroutine neatly
salva: There are several ways to do it, but IMO, the easiest and most straight forward is as follows: goto end
Um, two subroutines :)
sub foo { ... my $rc = fooFoo($ssh); $ssh->exit_session(); $ssh->close_session; return $rc; } sub fooFoo { my ($ssh) = @_; if ( !$ssh->start_session($ssh_host) ) { print "ERROR connecting to $ssh_host\n"; return 1; } my ( $ret, $err ) = $ssh->execute( 'command1', 'expect1' ); if ( $err || $ret =~ /Unknown command:/m ) { return 2; } my ( $ret, $err ) = $ssh->execute( 'command2', 'expect2' ); if ( $err || $ret =~ /Unknown command:/m ) { return 3; } return 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: exiting a subroutine neatly (Throwable)
by Anonymous Monk on May 05, 2015 at 10:11 UTC | |
by salva (Canon) on May 05, 2015 at 10:51 UTC | |
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 | |
|
Re^3: exiting a subroutine neatly
by salva (Canon) on May 05, 2015 at 10:13 UTC | |
by Anonymous Monk on May 05, 2015 at 10:16 UTC |