Untitled
unknown
plain_text
4 years ago
1.9 kB
6
Indexable
sub build_list_of_names
{
@my_list = ();
my $name;
open(FILE, "< name.txt") or die "Couldn't open file";
while (chomp($name = <FILE>))
{
push @my_list,$name;
}
close(FILE);
}
sub get_user_option
{
print("\n1.Serch for customer\n");
print("2. Add new customer\n");
print("3. Get all customer\n");
print("4. Quit\n");
print("\nSelect an option: ");
chomp($option_selected = <STDIN>);
return $option_selected;
}
sub get_customers
{
print("\nCustomers:\n\n");
my $count = 0;
foreach $name_of_customer (@my_list)
{
$count += 1;
print("$count. $name_of_customer\n");
}
}
sub search_for_customer
{
print("\nEnter name of customer: ");
chomp($name_of_customer = <STDIN>);
foreach $name(@my_list)
{
if ( lc($name_of_custmer) eq lc($name) )
{
print("\n$name was found.\n");
return;
}
}
}
sub add_new_customer
{
print("\nEnter name of new customer: ");
chomp($the_new_customer = <STDIN>);
$exit_status = push(@my_list, $the_new_customer);
if($exit_status) { print("\nNew customer added.\n");}
else{ print("\nSomthing went wrong!");}
}
&build_list_of_names();
$option_selected = &get_user_option();
while ($option_selected != 4)
{
if ($option_selected == 1)
{
&search_for_customer();
$option_selected = &get_user_option();
}
elsif ($option_selected == 2)
{
&add_new_customer();
$option_selected = &get_user_option();
}
elsif ($option_selected == 3)
{
&get_customers();
$option_selected = &get_user_option();
}
else
{
print("\nPlease select a valid option!\n");
$option_selected = &get_user_option();
}
}
open(FILE, "> name.txt");
foreach $name (@my_list)
{
chomp($name);
print(FILE "$name\n");
}
close(FILE);
print("\nExisting...\n");
exit;
Editor is loading...