Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

The documentation in CPAN does not say anything about a close() routine and with SSH1 it assumes that every connection is new. But W32Perl version uses SSH2 which is persistent. How do you properly close the instance? After creating 18 or so connections the script dies. I suspect I have created too many sessions that haven't been closed but can't figure out how to do it. When I chop up the list it works okay but I want to correct my programming style.
#!c:\perl\bin\perl.exe use strict; use Net::SSH::W32Perl; die "Error: Module Spreadsheet::WriteExcel needed. Please install and + retry.\n" unless ( require Spreadsheet::WriteExcel ); my $user = 'username'; my $password = 'password'; my $postfix = 'host.com'; my $cmd = 'lsallq'; my $excelfile = 'lsallq.xls'; die "Error: File $excelfile already exists. Please rename or delete a +nd rerun\n" if ( -e $excelfile ); # WriteExcel can't change an existing my @servers = ( 'servername1', 'servername2', 'servername3', 'servername4', 'servername5', 'servername6', 'servername7', 'servername8', 'servername9', 'servername10', 'servername11', 'servername12', 'servername13', 'servername14', 'servername15', 'servername16', 'servername17', 'servername18', 'servername19', 'servername20', 'servername21', 'servername22', 'servername24', 'servername25', ); my $workbook; die "Error: Could not create $excelfile.\n" unless ( $workbook = Sprea +dsheet::WriteExcel->new($excelfile) ); my $time = localtime(time()); my $worksheet = $workbook->add_worksheet("lsallq"); my $colnum = 0; foreach my $server (@servers) { my $rownum = 0; print "Connecting to $server\n"; my $ssh = Net::SSH::W32Perl->new($server.'.'.$postfix, port => 22 +); $ssh->login($user, $password); my($stdout, $stderr, $exit) = $ssh->cmd($cmd); if ($stderr) { print "ERROR: $stderr $exit\n"; } $worksheet->write_string($rownum,$colnum, $server); my @printers = split(/\n/,$stdout); sort @printers; print "Generating spreadsheet entries\n"; foreach my $printer (@printers) { $rownum++; $worksheet->write_string($rownum,$colnum, $printer); } $colnum++; $ssh->cmd('exit'); # explicit exit? Trying to fix die at 18th +server, how do you destroy instance correctly? } print "Done. I think\n";