On Monday, July 29, 2002, at 04:05 , Tómas Guðmundsson wrote:
[..]
> #!/usr/bin/perl
> use strict;
> use Cwd;
>
> my $phone_book = qw{
>   Fred 0123
>   John 4567
>   Bill 8901
> };

you might want to think of using a hash here
instead of a straight array, hence

my %phone_book = (
   Fred => 0123,
   John => 4567,
   Bill => 8901,
);

> my $selection = 1;
> do {
>  print "\n  Please select one choice";
>  print "\n  1. Enter name.";
>  print "\n  2. Quit.\n";
>
> chomp(my $selection = <STDIN>);
>
> if ($selection eq "1") {
>  chomp(my $number = <STDIN>);
>  print "$number  number is : $phone_book \n"
> }

hence
        
        my $name ;
                #you could do this as a numeric compare to make sure it is a 1

        if ( $selection eq 1 ) {
                chomp(my $number = <STDIN>);
                print "$name  number is : $phone_book{$name} \n"
        }

> } until ($selection eq "2");
>
> So this is where I've gotten to.
> When I enter 2 in the selection, it doesnt quit, but keeps on going and
> going and going.
> And when I enter a name, in selection 1, it always shows Bill's number

which is a bit peculiar, but you may find that with a 'hash'
it will be easier to deal with....

then you can look at more complex structures



ciao
drieux

---


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

Reply via email to