Another approach: File select_1.pl:
Output:use warnings; use strict; use Data::Dump; # for development/debug # you will have to open and process some kind of config file, # but i will use __DATA__ my %services; while (my $record = <DATA>) { my ($n, $service) = $record =~ m{ \A (\d+) \s* : \s* (.*?) \s* \z }xms; if (! defined($n) or ! defined($service)) { die "bad config file record '$record'" } if (exists $services{$n}) { die "duplicated service number $n: '$service'"; } $services{$n} = $service; } # dd \%services; # FOR DEBUG print "$_: $services{$_} \n" for sort { $a <=> $b } keys %services; my $n; CHOICE: { print "Please choose a number from the list above: "; chomp($n = <STDIN>); last CHOICE if exists $services{$n}; print "'$n' is not on the list. Please choose again. \n"; redo CHOICE; } print "You chose $n: '$services{$n}' \n"; __DATA__ 1: Recturing Svc 2: Finance 9: Payments 19: Mobile 29: Bankers
c:\@Work\Perl\monks\perlDevsWorld>perl select_1.pl 1: Recturing Svc 2: Finance 9: Payments 19: Mobile 29: Bankers Please choose a number from the list above: 3 '3' is not on the list. Please choose again. Please choose a number from the list above: xx 'xx' is not on the list. Please choose again. Please choose a number from the list above: 9 You chose 9: 'Payments'
Give a man a fish: <%-(-(-(-<
In reply to Re: pattern string match while reading from the file
by AnomalousMonk
in thread pattern string match while reading from the file
by perlDevsWorld
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |