On Mon, Mar 30, 2009 at 00:42, Chap Harrison <[email protected]> wrote:
> This may be beyond the beginner level.... I don't know.
>
> I'd like to prompt the user to type in a City, State, and Zip in one line.
> It's free-form, in that it's just for display, but I can make a pretty
> decent "suggestion" based upon data I've previously gathered.
>
> If I've gathered "IN-NewDurhamTwpMetro66765", I can convert it to "New
> Durham Twp Metro, IN 66765", which I"d like to pre-load the input area with
> when I prompt for City, State, and Zip. I'd like the user to have full
> readline capability, so he can forward-cursor up to Twp, and change it to
> Township (for example).
>
> I looked at Term::Readline::Gnu in CPAN and it's wa-a-ay over my head. Is
> there a simpler way, perhaps built into Perl, to prompt for terminal input
> and provide a preloaded string that can be edited?
>
> Thanks,
> Chap
>
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>
#!/usr/bin/perl
use strict;
use warnings;
use Term::ReadLine;
my $term = Term::ReadLine->new($0);
my @fields = qw/state city zip/;
my %rec;
while (1) {
my $coded = $term->readline("Enter coded location");
last if @r...@fields} = $coded =~ /^([A-Z]{2})-(\w+)([0-9]{5})$/;
print "please try again\n";
}
(my $prompt = $rec{city}) =~ s/(?<!^)([A-Z])/ $1/g;
$prompt .= ", $rec{state} $rec{zip}";
while (1) {
last if $rec{printable} = $term->readline("ender printable localtion:",
$prompt);
print "please try again\n";
}
use Data::Dumper;
print Dumper \%rec;
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/