1) Complete the following tasks: (25 pts.) a) Write a script to create a hash li
ID: 3705648 • Letter: 1
Question
1) Complete the following tasks: (25 pts.) a) Write a script to create a hash list for at least ten states (GA, NJ, CA, NY, VT, WA, PA, MD, CO, IL). b) Print 3 of states by accessing their keys. o) Replace the values of three states since you notice you make a mistake while assigning their values. d) Remove three of the states of your choice. e) Print the hast list in a tabular form (you may use any iteration structure to complete this task) Write a script that would create a hash list of the courses you are taking this semester, you must assigned the course abbreviation (ex. CS2215) and course description (Perl Scripting), finally display in a tabular form all the courses. (10 pts.) 2)Explanation / Answer
Que 1) a) Here we are asked to write a script which will create a hashlist for 10 states. Below is the code for creating the hash list in pearl. The syntax that you have used is correct. But in general we keep city code as the key and city name as the value in hash. Hence, we will reverse the key and value pairs that you have defined for more clarity.(refer to below code)
Que 1) b) Below is code for printing three states in pearl
Output of the above script
Que 1) c) Now we have asked to replace the values of the three states in hash, considering we have made a mistake while assigning values to it. Just for the understading we will update NewYork to New York; NewJersey to New Jersey and illinois to Illinois. Below is the code for the same.
#!/usr/bin/perl
Do note that in every script; we are copying state hash/dictionary everytime. For assignment purpose you can just write the required steps and not the whole code.
Que 1) d) In this question, we have asked to remove three states of our choice. We will remove Georgia, NewJersey and California. To delete these, simply we need to put delete in front of evey statement like delete $states{'GA'} thats it. Below is the code for the same.
#!/usr/bin/perl
Que 1) e) Here we need to print the values in tabular form. Below is the code for the same.
#!/usr/bin/perl
#!/usr/bin/perl
Hope this helps.
#!/usr/bin/perl
%states = ('GA' => 'Georgia', 'NJ' => 'New Jersey', 'CA' => 'California', 'NY' => 'New York', 'VT' => 'Vermont', 'WA' => 'Washington', 'PA' => 'Pennsylvania', 'MD' => 'Maryland', 'CO' => 'Colorado' , 'IL' => 'Illinois'); Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.