Hello Gajo,

A different approach to your problem is to use a data structure, e.g. an
array or hash.  Your script rewritten using an array,

#!/usr/bin/perl -w

my @option = ("one","two","three","four","five","six","maybe seven?");
print "Type in a number 1-", $#option+1, ": ";
$s = <STDIN>;
chomp $s ;
if ( $s =~ /\d+/ and defined $option[$s-1] ) {
  print "$option[$s-1]\n";
} else {
  print "not between 1-5\n";
}

Notice that it is quite easy to add, remove, or change items by modifying
@options.  You don't have to write any new code.

HTH,
- Robert

-----

At 03:18 PM 11/4/2002 +0100, Gajo Csaba wrote:
>print "Type in a number 1-5: ";
>$s = <STDIN>;
>SWITCH;
>{
> if ($s == 1) { print "one\n"; last SWITCH; }
> if ($s == 2) { print "two\n"; last SWITCH; }
> if ($s == 3) { print "three\n"; last SWITCH; }
> if ($s == 4) { print "four\n"; last SWITCH; }
> if ($s == 5) { print "five\n"; last SWITCH; }
>}


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

Reply via email to