Hey, trying to knock the rust off my Perl skilzzz and the monastery is juss the place with the Helpful Hardware .. errr software Man/woman/child/beast.
Anyway, what comments for improvement do you have on my code below?
#!/usr/bin/env perl
use strict;
my $user = 'brannont';
my @host = qw(
secdevfdsapp01
dopey
bonnie
) ;
sub ssh_string {
my $host = shift;
sprintf "%s@%s", $user, $host
}
sub printchoices {
print "\n\n";
print "ssh hosts\n";
print "---------\n";
for (my $i=0; $i <= $#host; ++$i) {
printf "[$i] %s\n" , $host[$i] ;
}
}
sub prompt {
print "\n\nssh to: " ;
}
sub getchoice {
prompt ;
my $choice = <STDIN> ;
chomp $choice;
return $choice;
}
sub mainloop {
{
printchoices;
my $c = getchoice ;
return $c if $c >= 0 and $c <= $#host ;
redo;
}
}
my $c = mainloop ;
my $host = $host[$c] ;
my $sshstr = ssh_string($host) ;
print $sshstr, "\n" ;
exec 'ssh', $sshstr ;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.