Hello Monks
I am trying to create a perl program only using hashes and loops that performs an address book function. you can add, delete, print or end program. I have started but I am having a problem in my code below the user is given a menu I have created the code for the add address as seen, after the user enters the name and address it is suppose to reshow the menu an run again, as seen below, but when user enters add again in the second menu the program quits. Any help here?
#!/usr/bin/perl -w
use strict;
use warnings;
my $input;
my $name;
my %directory = ();
print " Welcome to your own Personal Address Book!\n";
print " What would you like to do?\n";
print "add Add An Entry
del Delete An Entry
prn Print all Entries
end End Porgram
Choice: \n";
chomp ($input = <>);
for ($input eq "end")
{
if ($input eq "add")
{
print "Enter the Name you would like to add: \n";
chomp ($name = <>);
for ($input eq "add")
{
print "Enter an Address for $name\n";
chomp (my $address = <>);
$directory{$name} = $address;
print "add Add An Entry
del Delete An Entry
prn Print all Entries
end End Porgram
Choice: \n";
chomp ($input = <>);
}
}
elsif ($input eq "prn")
{
print "These are the people in your address book\n";
my @completed = keys %directory;
foreach my $who (@completed)
{
printf "%15s Name: Address: %s\n", $who, $directory{$who};
}
last;
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.