In exercise 3-3 from the lama book.

How do you make sure the user enters a number 1 thru 7?

The simple program is:

#!/usr/bin/perl
use warnings;
use strict;
my @names = qw/ fred betty barney dino wilma pebbles bamm-bamm /;
print "Enter some numbers from 1 to 7, one per line, then press Ctrl-Z:\n";
chomp(my @numbers = <STDIN>);
foreach (@numbers) {
    print "$names[ $_ -1]\n";
}

Just curious.. Thanks.

Reply via email to