Have a file with names, display the people in the file, then ask the person if they want to sign up, agree with Y, prompt them for their name, then add their name to the end of the file (if they say y) append the name to the end of the file using Perl.
This is the assignment, and this code below is mostly functional. However, when you input a name, it will remove all the other names that may have been in the file previously.
my $file = "name.txt";
# Use the open() function to open the file.
unless(open FILE, $file) {
# Die with error message
# if we can't open it.
die "\nUnable to open $file\n";
}
while(my $line = <FILE>) {
print $line;
}
open (fh, ">", "name.txt");
print "Do you want to sign up? \n";
$choice = <STDIN>;
$y = "yes\n";
if ($choice eq $y) {
print "Enter your name\n";
}
$a = <>;
# Writing to the file
print fh $a;
close(fh) or "Couldn't close the file";