Goffredo Saffioti wrote:

Myabe thi is not the best way but work fine.
Cya.

It works fine and inspired me to write two little programs demonstrating some other ways of getting user input without directly reading STDIN.


The first one is using Term::ReadLine. Install Term::ReadLine::Gnu for best experience. You can conveniently edit the line (it's actually a mini text editor), hit up-arrow to browse history and edit previous entries (in this example only after you entered few invalid values before), etc.

#!/usr/bin/perl -w

use strict;
use Quantum::Superpositions;
use Term::ReadLine;

$" = ', ';
my @a = qw(foo bar baz abc x y z);
my $term = new Term::ReadLine "Widget";

my $r;
do {$r = $term->readline("Choose widget: @a? ")} until $r eq any @a;

print "You have chosen $r.\n";

__END__

The second example is using Curses::UI. I find it quite cool. It pops up a simple text-mode window with question and buttons which you can select with arrows and Enter or even click with mouse.

#!/usr/bin/perl -w

use strict;
use Curses::UI;

my $cui = new Curses::UI;
my @a = qw(foo bar baz abc x y z);

my $r = $cui->dialog(
    -title => "Widget",
    -message => "Choose widget:",
    -buttons => [map {{-label=>$_}} @a],
);

$cui->dialog("You have chosen $a[$r].");

__END__

I've written this examples to show two nice and simple ways of getting user input in Perl programs. Please ask if anyone has any questions about them. Maybe someone knows any cooler way of getting user input in text mode?

--
ZSDC


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to