Hi,
I'm trying to write a perl program for a simple phone book. Means when the user enter a name, the phone book will search and display the name and the phone number of that person.
Below is my code:
#!/usr/bin/perl;
#playplay.pl
use warnings;
use strict;
my %phonebook = (
dog => "7777777",
cat => "8888888",
monster => "99999999",
);
print ("Please Enter a name to be search:\t");
$nama = <STDIN>;
if($phonebook{$nama})
{
print ("The phone number of $nama is $phonebook{$nama}");
}
else
{
print ("The phone number of $nama cannot be found.");
}
1. I just cannot look-up for a person's contact using variable. If use "dog" or "cat" directly to search, the program run ok.
2. The second problem is that i cant display the last 2 statements (line 20 & 25) in one line.
Thanks.