On 8/16/07, Sayed, Irfan (Irfan) <[EMAIL PROTECTED]> wrote:
> Thanks Chas but my req. is little bit different.
>
> As I said the data in the array will not be fixed so I don't know how
> many elements are present in the array. I don't want to just print the
> contents of the array but to use the contents of the array.
>
> For example if user select 3 option then my programme should pick up the
> third element of the array
snip

If the user selects 3 then subtract one and you get 2 the index of the
third element in the array.  My example code was not limited to 5
values, it was dynamic, but here it is again in whole script form:

#!/usr/bin/perl

use strict;
use warnings;

my @items;
#get a list of 4 to 8 items
push @items, "item $_" for 1 .. 4 + int rand 5;

print "select item:\n";
my $i = 1;
for my $item (@items) {
        print "\t" . $i++ . ". $item\n";
}
chomp(my $choice = <>);
die "bad choice" if $choice =~ /\D/ or $choice < 1 or $choice > @items;

print "you chose $items[$choice - 1]\n";

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to