Skip to content

Instantly share code, notes, and snippets.

@hernan604
Created October 17, 2013 21:24
Show Gist options
  • Select an option

  • Save hernan604/7032435 to your computer and use it in GitHub Desktop.

Select an option

Save hernan604/7032435 to your computer and use it in GitHub Desktop.
Basic readline example allows mount of a list of servers
use Term::ReadLine;
my $servers = [
{
servidor1 => 'mount /dev/x1 /mount/servidor1',
},
{
servidor2 => 'mount /dev/x2 /mount/servidor2',
},
{
servidor3 => 'mount /dev/x3 /mount/servidor3',
},
];
my $term = Term::ReadLine->new('Webdrive mounter');
my $prompt = "";
my $counter = 0 ;
foreach my $mount_point ( @$servers ) {
my $mount_name = (keys $mount_point)[0];
$prompt .= $counter . ': ' . $mount_name . $servers[$counter]->{ $mount_point } . "\n";
$counter++;
}
my $OUT = $term->OUT || \*STDOUT;
while ( defined( $_ = $term->readline( $prompt ) ) ) {
if ( defined @$servers[ $_ ] ) {
my $cmd = @$servers[$_]->{(keys @$servers[$_])[0]};
print $OUT $cmd;
} else {
print $OUT "Erro", "\n";
}
warn $@ if $@;
print $OUT $res, "\n" unless $@;
$term->addhistory($_) if /\S/;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment