#! /usr/bin/perl use strict; my %son_father; my $choice; my $name1; my $name2; my $name3; my $name4; my $newname; my $add_dad; %son_father = (Jeff => "Doug", Thomas => "Evan", Robert => "Jason", Bruce => "Richard", Clark => "Jon") ; my $menu = <); # fulfill the user request if ($choice eq 'a'){ print "Enter a male name: "; chomp (my $name1 = ucfirst lc ); } if (exists $son_father{$name1}) { print "Duplicate name -- try again!\n"; } else { print "Add a father: "; chomp (my $add_dad = ucfirst lc ); $son_father{$name1} = {$add_dad}; next; } if ($choice eq 'd') { print "Enter a male name: "; chomp (my $name2 = ucfirst lc ); } if (exists $son_father{$name2}) { delete $son_father{$name2}; } else { print "Sorry, couldn't find you -- try again later!"; next; } if ($choice eq 'e') { print "Come back again -- goodbye!"; last; next; } if ($choice eq 'g'){ print "Enter a son's name: "; chomp (my $name4 = ucfirst lc ); } if (exists $son_father{$name4}) { print "$son_father{$name4}\n"; next; } if ($choice eq 'o'){ my ($key, $value); foreach $value (sort keys %son_father){ print "$value\t$son_father{$value}\n"; next; } } if ($choice eq 'r'){ print "Enter a male name: "; chomp (my $name3 = ucfirst lc ); if (exists $son_father{$name3}) { print "Enter a new father name: "; chomp ($newname = ucfirst lc ); $son_father{$name3} = {$newname}; } else { print "Sorry, couldn't find you -- try again later!"; next; } } if ($choice ne 'a', $choice ne 'r', $choice ne 'o', $choice ne 'd', $choice ne 'e', $choice ne 'g') { print "Invalid choice, TRY AGAIN!\n"; next; } }