Assistance on complicated perl script

As a followup to my previous thread, I'm trying to make a complicated perl script that involves storing information from a text file into a hash, and giving the user the ability to change the information present/write the information currently inside the hash to a new file. This is the code I've made for it but I'm running into a lot of issues getting it to work so I could use some assistance-

use warnings;
use strict;
use Scalar::Util 'looks_like_number';
print "Welcome to an interactive Perl program. Enter either q or Q to terminate the program or c to continue. Enter your key now: "; 
my $input; 
$input = <STDIN>; 
chomp $input; 
if (($input ne "q") && ($input ne "Q") && ($input ne "c")) 
{
        print "Welcome to an interactive Perl program. Enter either q or Q to terminate the program or c to continue. Enter your key now: "; 
        $input = <STDIN>; 
        chomp $input; 
}
elsif (($input eq "q") || ($input eq "Q")) 
{
        exit; 
}
else
{
        my %patientinfo = do {
        open my $patients, '<', 'Patient.txt';
        map {
        my ($first, $second, @info) = split;
        "$first $second" => \@info;
        } <$patients>;
        };
        print "Would you like to change the information? (y/n): ";
        my $inp;
        $inp = <STDIN>;
        chomp $inp;
        if (($inp ne "y") && ($inp ne "n"))
        {
                print "Would you like to change the information? (y/n): ";
                my $inp;
                $inp = <STDIN>;
                chomp $inp;
        }
        elsif ($inp eq "y")
        {
                print "Give Patient's Name: ";
                my $inpname;
                $inpname = <STDIN>;
                chomp $inpname;
                if (exists $patientinfo{$inpname})
                {
                        print "Enter 1 to change the gender, 2 to change the DOB, or 3 to change the disease: ";
                        my $inpnum;
                        $inpnum = <STDIN>;
                        chomp $inpnum;
                        if (($inpnum != 1) && ($inpnum != 2) && ($inpnum != 3))
                        {
                                print "Enter 1 to change the gender, 2 to change the DOB, or 3 to change the disease: ";
                                my $inpnum;
                                $inpnum = <STDIN>;
                                chomp $inpnum;
                        }
                        elsif ($inpnum == 1)
                        {
                                print "Please enter (M/F): ";
                                my $gender;
                                $gender = <STDIN>;
                                chomp $gender;
                                if (($gender ne "M") && ($gender ne "F"))
                                {
                                        print "Please enter (M/F): "
                                        my $gender;
                                        $gender = <STDIN>;
                                        chomp $gender;
                                }
                                else
                                {
                                        $patientinfo[1] = $gender;
                                }
                        }
                        elsif ($inpnum == 2)
                        {
                                print "Please enter (xx/xx/xx): ";
                                my $dob;
                                $dob = <STDIN>;
                                chomp $dob;
                                $patientinfo[2] = $dob;
                        }
                        else ($inpnum == 3)
                        {
                                print "Please enter a disease: ";
                                my $disease;
                                $disease = <STDIN>;
                                chomp $disease;
                                if ($disease !~ /^-?0/ && looks_like_number($disease))
                                {
                                        print "Please enter a disease: ";
                                        my $disease;
                                        $disease = <STDIN>;
                                        chomp $disease;
                                }
                                else
                                {
                                        $patientinfo[3] = $disease;
                                }
                        }
                        print "Would you like to print patient information to a file? (n/y): ";
                        my $print;
                        $print = <STDIN>;
                        chomp $print;
                        if (($print ne "n") && ($print ne "y"))
                        {
                                print "Would you like to print patient information to a file? (n/y): ";
                                my $print;
                                $print = <STDIN>;
                                chomp $print;
}
                        elsif ($print eq "n")
                        {
                                exit;
                        }
                        else
                        {
                                print "Give Patient name: "
                                my $name;
                                $name = <STDIN>;
                                chomp $name;
                                if (exists $patientinfo{$name})
                                {
                                        open(my $patientinfo, '>', 'Info.txt');
                                        print "Name: $patientinfo[0]";
                                        print "Gender: $patieninfo[1]";
                                        print "DOB: $patientinfo[2]";
                                        print "Disease: $patientinfo[3]";
                                        close $patientinfo;
                                }
                                else
                                {
                                        print "Error, name not found.";
                                        exit;
                                }
                        }

                }
                else
                {
                        print "Error, name not found. Moving on to part 2.";
                        print "Would you like to print patient information to a file? (n/y): ";
                        my $print;
                        $print = <STDIN>;
                        chomp $print;
                        if (($print ne "n") && ($print ne "y"))
                        {
                                print "Would you like to print patient information to a file? (n/y): ";
                                my $print;
                                $print = <STDIN>;
                                chomp $print;
                        }
                        elsif ($print eq "n")
                        {
                                exit;
                        }
                        else
                        {
                                print "Give Patient name: "
                                my $name;
                                $name = <STDIN>;
                                chomp $name;
                                if (exists $patientinfo{$name})
                                {
                                        open(my $patientinfo, '>', 'Info.txt');
                                        print "Name: $patientinfo[0]";
                                        print "Gender: $patieninfo[1]";
                                        print "DOB: $patientinfo[2]";
                                        print "Disease: $patientinfo[3]";
                                        close $patientinfo;
                                }
                                else
                                {
                                        print "Error, name not found.";
                                        exit;
                                }
                        }
                }
        else
        {
                print "Would you like to print patient information to a file? (n/y): ";
                my $print;
                $print = <STDIN>;
                chomp $print;
                if (($print ne "n") && ($print ne "y"))
                {
                        print "Would you like to print patient information to a file? (n/y): ";
                        my $print;
                        $print = <STDIN>;
                        chomp $print;
                }
                elsif ($print eq "n")
                {
                        exit;
                }
                else
                {
                        print "Give Patient name: "
                        my $name;
                        $name = <STDIN>;
                        chomp $name;
                        if (exists $patientinfo{$name})
                        {
                                open(my $patientinfo, '>', 'Info.txt');
                                print "Name: $patientinfo[0]";
                                print "Gender: $patieninfo[1]";
                                print "DOB: $patientinfo[2]";
                                print "Disease: $patientinfo[3]";
                                close $patientinfo;
                        }
                        else
                        {
                                print "Error, name not found.";
                                exit;
                        }
                }
        }
}

Basically after the initial setup asking the user if they want to proceed with the program, I take the data inside a file called Patient.txt and store it in a hash with the first and last name making up the key while the rest of the columns make up the values. Then the program asks if the user wants to change the information. If they say yes then they are asked for a patient name, and if it doesn't exist it moves on to the second part. If it does it'll give the user the option to change values in the hash. After this it would move on to the second part where it asks to write the info of one patient to a new file called Info.txt. If the patient doesn't exist it'll display an error message and exit. The user would also reach this second part if the patient name they entered for part 1 didn't exist, or if they chose not to change anything in the hash at all.

Once agian, here is the info stored in Patient.txt (note that none of these people actually exist)-

Celena Standard  F 01/24/94 Cancer 
Jeniffer Orlowski  F 06/24/86 None
Brent Koehler  M 12/05/97  HIV
Mao Schleich  M 04/17/60  Cancer
Goldie Moultrie  F 04/05/96  None
Silva Rizzo  F 10/26/78  Amyloidosis
Leatha Papenfuss  F 10/15/97  CREST
Vita Sabb  F 05/28/87  Autism
Alyce Ugarte  F 12/21/64  HIV
Ela Prout  F 12/05/57  Autism
Mohamed Buchannon  M 07/24/91  Caner
Lael Stall  M 12/05/97  None

Any help and guidance is greatly appreciated, and if there is a question about my code I'll try and answer it to the best of my ability.

You have shown us your code. You have stated a general outline of how your code is supposed to work. What is your code doing that you don't want it to do? What isn't your code doing that you do want it to do?

Are you getting error messages when you run your code? If so, exactly what diagnostics are you seeing?

What outputs are you getting?

What outputs do you want to get?

First thing I'll note is that the very first line I submitted as my code is actually line 8 (due to comments I made on previous lines).

These are the error messages I'm receiving on my terminal-

syntax error at ./patient.pl line 73, near "my "
Global symbol "@patientinfo" requires explicit package name (did you forget to declare "my @patientinfo"?) at ./patient.pl line 79.
Global symbol "@patientinfo" requires explicit package name (did you forget to declare "my @patientinfo"?) at ./patient.pl line 88.
syntax error at ./patient.pl line 90, near "else ("
Global symbol "@patientinfo" requires explicit package name (did you forget to declare "my @patientinfo"?) at ./patient.pl line 105.
syntax error at ./patient.pl line 126, near "my "
Global symbol "$name" requires explicit package name (did you forget to declare "my $name"?) at ./patient.pl line 126.
Global symbol "$name" requires explicit package name (did you forget to declare "my $name"?) at ./patient.pl line 127.
Global symbol "$name" requires explicit package name (did you forget to declare "my $name"?) at ./patient.pl line 128.
Global symbol "$name" requires explicit package name (did you forget to declare "my $name"?) at ./patient.pl line 129.
Global symbol "@patientinfo" requires explicit package name (did you forget to declare "my @patientinfo"?) at ./patient.pl line 132.
Global symbol "@patieninfo" requires explicit package name (did you forget to declare "my @patieninfo"?) at ./patient.pl line 133.
Global symbol "@patientinfo" requires explicit package name (did you forget to declare "my @patientinfo"?) at ./patient.pl line 134.
Global symbol "@patientinfo" requires explicit package name (did you forget to declare "my @patientinfo"?) at ./patient.pl line 135.
syntax error at ./patient.pl line 167, near "my "

What I basically want as an output is for the program to run, and for there to be a new file in the directory called Info.txt with information inside it specific to how the user interacted with the program. For example, if the user changed the info for Celena Standard from F to M (in terms of the value for gender) and designated that name to be written into Info.txt, then that file should appear in the directory with this inside it-

Name: Celena Standard
Gender: M
DOB: 01/24/94
Disease: Cancer

Or on the flip side, say they didn't change the information and still chose that name (or they changed the info for one name but didn't choose that same person to write the info to Info.txt for the second part) then Info.txt would look identical to above but with the same values present in the Patient.txt file I gave above.

I haven't gone through your entire program or understood the logic, but some of the messages seem to be due to standard beginner errors.

syntax error at ./patient.pl line 73, near "my "

Check the line right above the "my " on line 73. You are probably missing a semi-colon. All Perl executable statements end with a semi-colon.

Global symbol "@patientinfo" requires explicit package name (did you forget to declare "my @patientinfo"?) at ./patient.pl line 79.
Global symbol "@patientinfo" requires explicit package name (did you forget to declare "my @patientinfo"?) at ./patient.pl line 88.

You have declared "patientinfo" as a hash i.e. "%patientinfo", but are using it as a list/array i.e. "$patientinfo[1] = $gender;"
Check the Perl documentation for the differences between lists and hashes and decide what you want to do.

syntax error at ./patient.pl line 90, near "else ("

"else" cannot be followed by a condition i.e. "else ($inpnum == 3)" is a syntax error. The fact that you are using an "else" branch means that you have exhausted all your conditions and want a catch-all provision at the end. If you do want to test a condition, then use "elsif" instead. But do understand it is not the same as "else".

Global symbol "$name" requires explicit package name (did you forget to declare "my $name"?) at ./patient.pl line 126.

This one is interesting because although you have done a strict declaration of $name i.e. "my $name", Perl sees "my" as continuation of the previous line. That's because the previous line does not end with a semi-colon.
Again, all Perl executable statements end with a semi-colon.

Global symbol "@patieninfo" requires explicit package name (did you forget to declare "my @patieninfo"?) at ./patient.pl line 133.

Check the spelling: "patieninfo" is not the same as "patientinfo". Thereafter, decide what you want to use - the hash or the list. Or if you want to declare a separate list etc.

Use the suggestions above to fix the rest of the errors. I haven't gone through your program thoroughly, but I hope the above pointers help you in at least running the program successfully.

1 Like

I haven't gone through your script in detail either, but I did quickly find at least four print statements in your code that are not properly terminated as suggested by durden_tyler. If you fix those, you'll get considerably fewer errors.

Okay so an update (sorry if this is late). I managed to get the program to run, but I'm not getting my desired output. When I get to part 2 without changing any information, and I input the name say, Celena Standard, I get these messages-

Use of uninitialized value $patientinfo[1] in concatenation (.) or string at ./patient.pl line 209, <STDIN> line 4.
Use of uninitialized value $patientinfo[2] in concatenation (.) or string at ./patient.pl line 210, <STDIN> line 4.
Use of uninitialized value $patientinfo[3] in concatenation (.) or string at ./patient.pl line 211, <STDIN> line 4.

The Info.txt file appears in my directory but with nothing in it at all too.

Also for some reason my error checking at the very beginning isn't working properly. If the user inputs a 'c' or 'q' it works fine but if they say, enter '3' they get prompted again and if they enter an incorrect input again the program exits even if they didn't hit 'q' (it even exits if they hit 'c' when it should continue the program with this input). I am really confused as to why I'm running into this problem because I set up the beginning of an interactive Perl script in the past with those same lines of code and it worked just fine.

EDIT: I've fixed the issue with the beginning of my program

Since it is printing "$patientinfo[1]" in the error message, my hunch is that you have now added a declaration of the array "patientinfo".
However, that array never got populated because you have a hash "patientinfo" near the beginning of your program. Since the array is uninitialized, Perl prints that message.

The file Info.txt has nothing in it because the lines that were supposed to write in that file errored out as seen above. The open() function created an empty file and the close() function closed that empty file.

use warnings;
use strict;
use Scalar::Util 'looks_like_number';
print "Welcome to an interactive Perl program. Enter either q or Q to terminate the program or c to continue. Enter your key now: "; #prompts the user to enter either q Q or c
my $input; #declares the variable input
$input = <STDIN>; #the user input will be stored in the variable called input
chomp $input; #the value in the variable called input will be chomped
while (($input ne "q") && ($input ne "Q") && ($input ne "c")) #this conditional is for checking if the user inputted anything other than q Q or c
{
	print "Welcome to an interactive Perl program. Enter either q or Q to terminate the program or c to continue. Enter your key now: "; #if the user inputted anything other than q Q or c then they will be prompted again
	$input = <STDIN>; #the new user input will be stored in the variable called input
	chomp $input; #the new value in the variable called input will be chomped
}
if (($input eq "q") || ($input eq "Q")) #this conditional is for checking if the user inputed either q or Q
{
	exit; #if they inputted either q or Q then the program will stop running
}
else
{
	my %patientinfo = do {
	open my $patientinfo, '<', 'Patient_Info.txt';
	map {
	my ($first, $second, @info) = split;
	"$first $second" => \@info;
	} <$patientinfo>;
	}; #this is for creating the hash that stores the info inside the text file
	my @patientinfo = <%patientinfo>; #I also store the info from the hash inside an array
	print "Would you like to change the information? (y/n): "; #prompts the user
	my $inp; #declares variable
	$inp = <STDIN>; #takes the users input
	chomp $inp; #chomps the users input
	while (($inp ne "y") && ($inp ne "n")) #conditional loop to check and see if the users input doesn't equal y or n
	{
		print "Would you like to change the information? (y/n): "; #prompts the user again 
		my $inp; #declares variable again
		$inp = <STDIN>; #takes the users input again
		chomp $inp;  #chomps the users input again
	}
	if ($inp eq "y") #checks to see if the users input equals y
	{
		print "Give Patient's Name: "; #prompts the user
		my $inpname; #declares variable
		$inpname = <STDIN>; #takes the users input
		chomp $inpname; #chomps the users input
		if (exists $patientinfo{$inpname}) #checks to see if patient name exists in hash
		{
			print "Enter 1 to change the gender, 2 to change the DOB, or 3 to change the disease: "; #prompts the user
			my $inpnum; #declares variable
			$inpnum = <STDIN>; #takes the users input
			chomp $inpnum; #chomps the users input
			while (($inpnum != 1) && ($inpnum != 2) && ($inpnum != 3)) #conditional loop to check and see if the users input doesn't equal to 1 2 or 3
			{
				print "Enter 1 to change the gender, 2 to change the DOB, or 3 to change the disease: "; #prompts the user
                        	my $inpnum; #declares variable
                        	$inpnum = <STDIN>; #takes the users input
                        	chomp $inpnum; #chomps the users input
			}
			if ($inpnum == 1) #checks to see if user input equals to 1
			{
				print "Please enter (M/F): "; #prompts the user
				my $gender; #declares variable
				$gender = <STDIN>; #takes the users input
				chomp $gender; #chomps the users input
				while (($gender ne "M") && ($gender ne "F")) #checks to see if the user input doesn't equal to either M or F
				{
					print "Please enter (M/F): "; #prompts the user again
					my $gender; #declares variable again
					$gender = <STDIN>; #takes the users input again
					chomp $gender; #chomps the users input again
				}
				if (($gender eq "M") || ($gender eq "F"))
				{
					$patientinfo[1] = $gender; #changes the value inside the array
				}
				else
				{
					;
				}
			}
			elsif ($inpnum == 2) #checks to see if user input equals to 2
			{
				print "Please enter (xx/xx/xx): "; #prompts the user
				my $dob; #declares variable
				$dob = <STDIN>; #takes the users input
				chomp $dob; #chomps the users input
				$patientinfo[2] = $dob; #changes the value inside the array
			}
			else
			{
				print "Please enter a disease: "; #prompts the user
				my $disease; #declares variable
				$disease = <STDIN>; #takes the users input
				chomp $disease; #chomps the users input
				while ($disease !~ /^-?0/ && looks_like_number($disease)) #checks to see if the user input was a number
				{
					print "Please enter a disease: "; #prompts the user again
					my $disease; #declares variable again
					$disease = <STDIN>; #takes the users input again
					chomp $disease; #chomps the users input again
				} 
					$patientinfo[3] = $disease; #changes the value insude the array
				}
			}
			print "Would you like to print patient information to a file? (n/y): "; #prompts the user
                        my $print; #declares variable
                        $print = <STDIN>; #takes the users input
                        chomp $print; #chomps the users input
                        while (($print ne "n") && ($print ne "y")) #checks to see if user input doesn't equal to either n or y
                        {
                                print "Would you like to print patient information to a file? (n/y): "; #prompts the user
                                my $print; #declares variable
                                $print = <STDIN>; #takes the users input
                                chomp $print; #chomps the users input
                        }
                        if ($print eq "n") #checks to see if user input equals n
                        {
                                exit; #exits the script
                        }
                        else
                        {
                                print "Give Patient name: "; #prompts the user
                                my $names1 = <STDIN>; #declares a variable and takes the users input
                                chomp $names1; #chomps the users input
                                if (exists $patientinfo{$names1}) #checks to see if the users input exists in the hash
                                {
                                        open(my $patientinfo, '>', 'Info_Accessed.txt');
                                        print "Name: $patientinfo[0]";
                                        print "Gender: $patientinfo[1]";
                                        print "DOB: $patientinfo[2]";
                                        print "Disease: $patientinfo[3]";
                                        close $patientinfo; #writes all the info to a new text file called Info_Accessed.txt
                                }
                                else
                                {
                                        print "Error, name not found."; #displays an error message for the user
                                        exit; #exits the script
                                }
                        }
		}
		else
		{
			print "Error, name not found. Moving on to part 2."; #displays an error message for the user
			print "Would you like to print patient information to a file? (n/y): "; #prompts the user
			my $print1; #declare a variable
			$print1 = <STDIN>; #takes the users input
			chomp $print1; #chomps the users input
			while (($print1 ne "n") && ($print1 ne "y")) #checks to see if the users input doesn't equal to either n or y
			{
				print "Would you like to print patient information to a file? (n/y): "; #prompts the user
                        	my $print1; #declares variable
                        	$print1 = <STDIN>; #takes the users input
                        	chomp $print1; #chomps the users input
			}
			if ($print1 eq "n") #checks to see if the users input equals n
			{
				exit; #exits the script
			}
			else
			{
				print "Give Patient name: "; #prompts the user
				my $na = <STDIN>; #declares a variable and takes the users input
				chomp $na; #chomps the users input
				if (exists $patientinfo{$na}) #checks to see if the users input exists in the hash
				{
					open(my $patientinfo, '>', 'Info_Accessed.txt'); 
					print "Name: $patientinfo[0]";
					print "Gender: $patientinfo[1]";
					print "DOB: $patientinfo[2]";
					print "Disease: $patientinfo[3]";
					close $patientinfo; #writes all the info to a new text file called Info_Accessed.txt
				}
				else
				{
					print "Error, name not found."; #displays an error message for the user
					exit; #exits the script
				}
			}
		}
	***else***
	{
		print "Would you like to print patient information to a file? (n/y): "; #prompts the user
        	my $print; #declares variable
        	$print = <STDIN>; #tales the users input
        	chomp $print; #chomps the users input
        	while (($print ne "n") && ($print ne "y")) #checks to see if the users input doesn't equal n and y
        	{
                	print "Would you like to print patient information to a file? (n/y): "; #prompts the user again
                	my $print; #declares variable again
                	$print = <STDIN>; #takes the users input again
                	chomp $print; #chomps the users input again
        	}
        	if ($print eq "n") #checks to see if the user input equals n
        	{
                	exit; #exits the script
        	}
        	else
        	{
                	print "Give Patient name: "; #prompts the user
                	my $na1 = <STDIN>; #declares a variable and takes the users input
                	chomp $na1; #chomps the users input
                	if (exists $patientinfo{$na1}) #checks to see if the users input exists in the hash
                	{
                		open(my $patientinfo, '>', 'Info_Accessed.txt');
                        	print "Name: $patientinfo[0]";
                        	print "Gender: $patientinfo[1]";
                        	print "DOB: $patientinfo[2]";
                        	print "Disease: $patientinfo[3]";
                        	close $patientinfo; #writes all the info to a new text file called Info_Accessed.txt
			}
                	else
                	{
                        	print "Error, name not found."; #displays an error message for the user
                        	exit; #exits the script
                	}
		}
	}
***}***

I can't run my program anymore because there are syntax errors at the parts of my code towards the end I highlighted with asterisks. Any idea why?

That's because it is an "orphan" else branch.
It does not have a corresponding if-elsif branch.
I have added line numbers to your code and added color coding to make it easier to spot the if/elsif/else branches.
The closing brace at line 217 is for the opening brace at line 19.

 $ cat -n patient.pl
     1  use warnings;
     2  use strict;
     3  use Scalar::Util 'looks_like_number';
     4  print "Welcome to an interactive Perl program. Enter either q or Q to terminate the program or c to continue. Enter your key now: "; #prompts the user to enter either q Q or c
     5  my $input; #declares the variable input
     6  $input = <STDIN>; #the user input will be stored in the variable called input
     7  chomp $input; #the value in the variable called input will be chomped
     8  while (($input ne "q") && ($input ne "Q") && ($input ne "c")) #this conditional is for checking if the user inputted anything other than q Q or c
     9  {
    10          print "Welcome to an interactive Perl program. Enter either q or Q to terminate the program or c to continue. Enter your key now: "; #if the user inputted anything other than q Q or c then they will be prompted again
    11          $input = <STDIN>; #the new user input will be stored in the variable called input
    12          chomp $input; #the new value in the variable called input will be chomped
    13  }
   14  if (($input eq "q") || ($input eq "Q")) #this conditional is for checking if the user inputed either q or Q
    15  {
   16          exit; #if they inputted either q or Q then the program will stop running
   17  }
   18  else
    19  {
   20          my %patientinfo = do {
    21          open my $patientinfo, '<', 'Patient_Info.txt';
    22          map {
    23          my ($first, $second, @info) = split;
    24          "$first $second" => \@info;
    25          } <$patientinfo>;
    26          }; #this is for creating the hash that stores the info inside the text file
    27          my @patientinfo = <%patientinfo>; #I also store the info from the hash inside an array
    28          print "Would you like to change the information? (y/n): "; #prompts the user
    29          my $inp; #declares variable
    30          $inp = <STDIN>; #takes the users input
    31          chomp $inp; #chomps the users input
    32          while (($inp ne "y") && ($inp ne "n")) #conditional loop to check and see if the users input doesn't equal y or n
    33          {
    34                  print "Would you like to change the information? (y/n): "; #prompts the user again
    35                  my $inp; #declares variable again
    36                  $inp = <STDIN>; #takes the users input again
    37                  chomp $inp;  #chomps the users input again
    38          }
   39          if ($inp eq "y") #checks to see if the users input equals y
    40          {
   41                  print "Give Patient's Name: "; #prompts the user
    42                  my $inpname; #declares variable
    43                  $inpname = <STDIN>; #takes the users input
    44                  chomp $inpname; #chomps the users input
    45                  if (exists $patientinfo{$inpname}) #checks to see if patient name exists in hash
    46                  {
    47                          print "Enter 1 to change the gender, 2 to change the DOB, or 3 to change the disease: "; #prompts the user
    48                          my $inpnum; #declares variable
    49                          $inpnum = <STDIN>; #takes the users input
    50                          chomp $inpnum; #chomps the users input
    51                          while (($inpnum != 1) && ($inpnum != 2) && ($inpnum != 3)) #conditional loop to check and see if the users input doesn't equal to 1 2 or 3
    52                          {
    53                                  print "Enter 1 to change the gender, 2 to change the DOB, or 3 to change the disease: "; #prompts the user
    54                                  my $inpnum; #declares variable
    55                                  $inpnum = <STDIN>; #takes the users input
    56                                  chomp $inpnum; #chomps the users input
    57                          }
    58                          if ($inpnum == 1) #checks to see if user input equals to 1
    59                          {
    60                                  print "Please enter (M/F): "; #prompts the user
    61                                  my $gender; #declares variable
    62                                  $gender = <STDIN>; #takes the users input
    63                                  chomp $gender; #chomps the users input
    64                                  while (($gender ne "M") && ($gender ne "F")) #checks to see if the user input doesn't equal to either M or F
    65                                  {
    66                                          print "Please enter (M/F): "; #prompts the user again
    67                                          my $gender; #declares variable again
    68                                          $gender = <STDIN>; #takes the users input again
    69                                          chomp $gender; #chomps the users input again
    70                                  }
    71                                  if (($gender eq "M") || ($gender eq "F"))
    72                                  {
    73                                          $patientinfo[1] = $gender; #changes the value inside the array
    74                                  }
    75                                  else
    76                                  {
    77                                          ;
    78                                  }
    79                          }
    80                          elsif ($inpnum == 2) #checks to see if user input equals to 2
    81                          {
    82                                  print "Please enter (xx/xx/xx): "; #prompts the user
    83                                  my $dob; #declares variable
    84                                  $dob = <STDIN>; #takes the users input
    85                                  chomp $dob; #chomps the users input
    86                                  $patientinfo[2] = $dob; #changes the value inside the array
    87                          }
    88                          else
    89                          {
    90                                  print "Please enter a disease: "; #prompts the user
    91                                  my $disease; #declares variable
    92                                  $disease = <STDIN>; #takes the users input
    93                                  chomp $disease; #chomps the users input
    94                                  while ($disease !~ /^-?0/ && looks_like_number($disease)) #checks to see if the user input was a number
    95                                  {
    96                                          print "Please enter a disease: "; #prompts the user again
    97                                          my $disease; #declares variable again
    98                                          $disease = <STDIN>; #takes the users input again
    99                                          chomp $disease; #chomps the users input again
   100                                  }
   101                                          $patientinfo[3] = $disease; #changes the value insude the array
   102                                  }
   103                          }
   104                          print "Would you like to print patient information to a file? (n/y): "; #prompts the user
   105                          my $print; #declares variable
   106                          $print = <STDIN>; #takes the users input
   107                          chomp $print; #chomps the users input
   108                          while (($print ne "n") && ($print ne "y")) #checks to see if user input doesn't equal to either n or y
   109                          {
   110                                  print "Would you like to print patient information to a file? (n/y): "; #prompts the user
   111                                  my $print; #declares variable
   112                                  $print = <STDIN>; #takes the users input
   113                                  chomp $print; #chomps the users input
   114                          }
   115                          if ($print eq "n") #checks to see if user input equals n
   116                          {
   117                                  exit; #exits the script
   118                          }
   119                          else
   120                          {
   121                                  print "Give Patient name: "; #prompts the user
   122                                  my $names1 = <STDIN>; #declares a variable and takes the users input
   123                                  chomp $names1; #chomps the users input
   124                                  if (exists $patientinfo{$names1}) #checks to see if the users input exists in the hash
   125                                  {
   126                                          open(my $patientinfo, '>', 'Info_Accessed.txt');
   127                                          print "Name: $patientinfo[0]";
   128                                          print "Gender: $patientinfo[1]";
   129                                          print "DOB: $patientinfo[2]";
   130                                          print "Disease: $patientinfo[3]";
   131                                          close $patientinfo; #writes all the info to a new text file called Info_Accessed.txt
   132                                  }
   133                                  else
   134                                  {
   135                                          print "Error, name not found."; #displays an error message for the user
   136                                          exit; #exits the script
   137                                  }
   138                          }
  139                  }
  140                  else
   141                  {
  142                          print "Error, name not found. Moving on to part 2."; #displays an error message for the user
   143                          print "Would you like to print patient information to a file? (n/y): "; #prompts the user
   144                          my $print1; #declare a variable
   145                          $print1 = <STDIN>; #takes the users input
   146                          chomp $print1; #chomps the users input
   147                          while (($print1 ne "n") && ($print1 ne "y")) #checks to see if the users input doesn't equal to either n or y
   148                          {
   149                                  print "Would you like to print patient information to a file? (n/y): "; #prompts the user
   150                                  my $print1; #declares variable
   151                                  $print1 = <STDIN>; #takes the users input
   152                                  chomp $print1; #chomps the users input
   153                          }
   154                          if ($print1 eq "n") #checks to see if the users input equals n
   155                          {
   156                                  exit; #exits the script
   157                          }
   158                          else
   159                          {
   160                                  print "Give Patient name: "; #prompts the user
   161                                  my $na = <STDIN>; #declares a variable and takes the users input
   162                                  chomp $na; #chomps the users input
   163                                  if (exists $patientinfo{$na}) #checks to see if the users input exists in the hash
   164                                  {
   165                                          open(my $patientinfo, '>', 'Info_Accessed.txt');
   166                                          print "Name: $patientinfo[0]";
   167                                          print "Gender: $patientinfo[1]";
   168                                          print "DOB: $patientinfo[2]";
   169                                          print "Disease: $patientinfo[3]";
   170                                          close $patientinfo; #writes all the info to a new text file called Info_Accessed.txt
   171                                  }
   172                                  else
   173                                  {
   174                                          print "Error, name not found."; #displays an error message for the user
   175                                          exit; #exits the script
   176                                  }
   177                          }
  178                  }
  179          ***else***
   180          {
   181                  print "Would you like to print patient information to a file? (n/y): "; #prompts the user
   182                  my $print; #declares variable
   183                  $print = <STDIN>; #tales the users input
   184                  chomp $print; #chomps the users input
   185                  while (($print ne "n") && ($print ne "y")) #checks to see if the users input doesn't equal n and y
   186                  {
   187                          print "Would you like to print patient information to a file? (n/y): "; #prompts the user again
   188                          my $print; #declares variable again
   189                          $print = <STDIN>; #takes the users input again
   190                          chomp $print; #chomps the users input again
   191                  }
   192                  if ($print eq "n") #checks to see if the user input equals n
   193                  {
   194                          exit; #exits the script
   195                  }
   196                  else
   197                  {
   198                          print "Give Patient name: "; #prompts the user
   199                          my $na1 = <STDIN>; #declares a variable and takes the users input
   200                          chomp $na1; #chomps the users input
   201                          if (exists $patientinfo{$na1}) #checks to see if the users input exists in the hash
   202                          {
   203                                  open(my $patientinfo, '>', 'Info_Accessed.txt');
   204                                  print "Name: $patientinfo[0]";
   205                                  print "Gender: $patientinfo[1]";
   206                                  print "DOB: $patientinfo[2]";
   207                                  print "Disease: $patientinfo[3]";
   208                                  close $patientinfo; #writes all the info to a new text file called Info_Accessed.txt
   209                          }
   210                          else
   211                          {
   212                                  print "Error, name not found."; #displays an error message for the user
   213                                  exit; #exits the script
   214                          }
   215                  }
   216          }
  217  ***}***
   218
 $
$
 

A few points to remember about if/elsif/else branch:
1) If you're going to use this branch, then there must be exactly 1 "if" branch. It must be at the beginning. It must be followed by a condition. You cannot have more than one "if" branch in the same "if/elsif/else" branch.
2) Thereafter, there can be 0, 1 or more "elsif" branch(es). They must be after the "if" branch. They must be followed by a condition i.e. any expression or string that evaluates to true or false.
3) Thereafter, there can be 0 or 1 "else" branch. They do not check any condition. You cannot have more than 1 "else" branch. It must be at the end, after the "if" or "elsif" branches.

---------- Post updated at 11:10 AM ---------- Previous update was at 10:59 AM ----------

By the way, if you use editors like vim, gvim, emacs etc. then they have keyboard shortcuts that allow you to "jump" between opening/closing braces.
If you use GUI editors on Windows or Linux, then many of them show vertical lines on the left that span entire "if", "elsif", "else" brances.
In some of them, you could even click on small icons on the left to expand or collapse these brances.
These are small things, but they make coding much easier.