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-
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)-
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.
Moderator's Comments:
Please use CODE tags (not ICODE tags) when displaying full-line and multi-line sample input, output, and code segments.
Last edited by Don Cragun; 05-22-2017 at 02:09 AM..
Reason: Change ICODE tags to CODE tags again.
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?
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-
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-
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.
Moderator's Comments:
I repeat: Please use CODE tags (not ICODE tags) when displaying full-line and multi-line sample input, output, and code segments.
Last edited by Don Cragun; 05-22-2017 at 05:27 PM..
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.
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.
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.
"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".
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.
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.
This User Gave Thanks to durden_tyler For This Post:
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-
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
...
When I get to part 2 without changing any information, and I input the name say, Celena Standard, I get these messages-
The Info.txt file appears in my directory but with nothing in it at all too.
...
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.
Hello,
also with the help of some great users of this forum, I have created following shell script.
MM=120
GG=5000
# get size of directory
szm=$(du -s --block-size M ./192.168.1.xxx | awk '{print int($0)}')
data=$(date --rfc-3339=seconds)
if ; then # too big delete older files
... (10 Replies)
Hello,
Please advise. Scoured this site, as well as google for answers. However if you do not know what to search for, it's a bit hard to find answers.
INPUT:
ACTASS=
802
BASECOS=
279
COSNCHG=
3
CUSCOS=
52
UPLDCOS=
2
DESIRED OUTPUT:
ACTASS=802
BASECOS=279 (13 Replies)
I have a text file for which i need a script which does some fancy search and replace.
Basically i want to loop through each line, if i find an occurance of certain string format then i want to carry on search on replace another line, once i replaced this line i will contine to search for the... (7 Replies)
PFA file "color.txt".
Note : There is no newline character in the file. I have manually inserted the newline char to make it easy to understand.
I am expecting out in the form as specified in second file "out.txt"
I need a perl script to perform the task.
Thanks in advance. (2 Replies)
I need to write a perl script to execute external programs and grab the output and return code. Each program should be killed if it has not completed within X seconds.
Imagine that the script goes something like this :
@commands = &get_commands();
foreach $cmd (@commands) {
$pid =... (4 Replies)
ok, so what i want to do is make a script that will do the following:
take out from a command in the terminal
put that output into a text file already on my computer.
the only thing is that i need to put the output in the file kinda weird: i need to take it and put each character of output... (13 Replies)
I have a script that I need to create tha involves moving files and renaming them(see previous post)
Are there any websites with user made shell scripts? (5 Replies)
I'm attempting to create a Perl script that will:
Take the contents of the usernames.tmp file
(usernames.tmp is created from an awk one-liner ran against /etc/passwd)
Take one line at a time and pass it to the su command as a users name.
This should go on until there is no more name to... (10 Replies)
I need to query a http site and then parse the xml results, this works well if I use the string in IE but I require an automated solution.
I have tried using the following as well as HTTP::Request, nothing seems to work any suggestions would be appreciated, I have tried diffrnt things I found on... (7 Replies)