Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: exiting a subroutine neatly

by basiliscos (Pilgrim)
on May 05, 2015 at 15:53 UTC ( [id://1125750]=note: print w/replies, xml ) Need Help??


in reply to exiting a subroutine neatly

Try to use Guard (there are alternatives, but I'm satisfied with that one). So, your code would look like:

use Guard; # inside your routine ... my $guard = scope_guard { $ssh->exit_session; $ssh->close_session; } ... return 5;

Please note, the scope guard will be executed even if your code dies somewhere after guard definition.

WBR, basiliscos.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1125750]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found