xSirPotsAlotx
New member
!/usr/bin/perl -w
use strict;
use warnings;
my %directory = ();
my $input;
my $add = "add";
my $print = "print";
my $ended = "end";
my $deleted = "delete";
print " Welcome to your own Personal Address Book!\n";
print " What would you like to do?\n";
print "add Add An Entry
Delete Delete An Entry
Print Print all Entries
Choice: \n";
chomp ($input = <>);
if ($input eq $add )
{
print "Enter the Name you would like to add: ";
while (my $name = <>)
{
chomp $name;
if ($name eq $ended)
{
last;
}
if ($name eq $print)
{
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;
}
if ($name eq $deleted)
{
delete $directory{'$address'};
}
else
{
print "Enter an Address for $name\n";
chomp (my $address = <>);
$directory {$name} = $address;
print "Saved! Type a name again to add or Print End or Delete ";
}
}
}
else
{
print "That was not a valid entry, please re-run this program\n";
}
I am trying to have this program kick out after the user has either completed the if statement inside, basically I need this loop in a loop any idea's?
use strict;
use warnings;
my %directory = ();
my $input;
my $add = "add";
my $print = "print";
my $ended = "end";
my $deleted = "delete";
print " Welcome to your own Personal Address Book!\n";
print " What would you like to do?\n";
print "add Add An Entry
Delete Delete An Entry
Print Print all Entries
Choice: \n";
chomp ($input = <>);
if ($input eq $add )
{
print "Enter the Name you would like to add: ";
while (my $name = <>)
{
chomp $name;
if ($name eq $ended)
{
last;
}
if ($name eq $print)
{
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;
}
if ($name eq $deleted)
{
delete $directory{'$address'};
}
else
{
print "Enter an Address for $name\n";
chomp (my $address = <>);
$directory {$name} = $address;
print "Saved! Type a name again to add or Print End or Delete ";
}
}
}
else
{
print "That was not a valid entry, please re-run this program\n";
}
I am trying to have this program kick out after the user has either completed the if statement inside, basically I need this loop in a loop any idea's?