ealance Technology 1) Complete the following tasks: (25 pts.) PERL eingucige a s
ID: 3705671 • Letter: E
Question
ealance Technology 1) Complete the following tasks: (25 pts.) PERL eingucige 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. e) 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 t course abbreviation (ex. C$2215) and course description (Perl Scripting), finally display in a tabular form all the courses. (10 pts.) 2)Explanation / Answer
Solution 1)
a) We have to write a script that creates a hash list for at least given 10 states. This is as follows:
#!/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');
b) Code for print 3 of states by accessing their keys:
#!/usr/bin/perl
%states = ('GA' => 'Georgia', 'NJ' => 'NewJersey', 'CA' => 'California', 'NY' => 'NewYork', 'VT' => 'Vermont', 'WA' => 'Washington', 'PA' => 'Pennsylvania', 'MD' => 'Maryland', 'CO' => 'Colorado' , 'IL' => 'illinois');
print "$states{'GA'} ";
print "$states{'NJ'} ";
print "$states{'CA'} ";
Output would be like this:
Georgia
NewJersey
California
c) Code for replace the values of three states:
#!/usr/bin/perl
%states = ('GA' => 'Georgia', 'NJ' => 'NewJersey', 'CA' => 'California', 'NY' => 'NewYork', 'VT' => 'Vermont', 'WA' => 'Washington', 'PA' => 'Pennsylvania', 'MD' => 'Maryland', 'CO' => 'Colorado' , 'IL' => 'illinois');
$states{'NJ'} = 'New Jersey';
$states{'NY'} = 'New York';
$states{'IL'} = 'Illinois';
d) Code for removing the three states:
#!/usr/bin/perl
%states = ('GA' => 'Georgia', 'NJ' => 'NewJersey', 'CA' => 'California', 'NY' => 'NewYork', 'VT' => 'Vermont', 'WA' => 'Washington', 'PA' => 'Pennsylvania', 'MD' => 'Maryland', 'CO' => 'Colorado' , 'IL' => 'illinois');
delete $states{'CA'};
delete $states{'NY'};
delete $states{'CO'};
e) Code for print the hash list in tabular form:
#!/usr/bin/perl
%states = ('GA' => 'Georgia', 'NJ' => 'NewJersey', 'CA' => 'California', 'NY' => 'NewYork', 'VT' => 'Vermont', 'WA' => 'Washington', 'PA' => 'Pennsylvania', 'MD' => 'Maryland', 'CO' => 'Colorado' , 'IL' => 'illinois');
while (($key, $value) = each (%states))
{
$value = $states{$key};
print " $key $value ";
}
Solution 2) Script that would create a hash list of the courses you are taking this semester:
#!/usr/bin/perl
%courses = ('CS2215' => 'Pearl Scripting', 'CS2216' => 'Web Technologies', 'CS2217' => 'Programming Langauges', 'CS2218' => 'Machine Learning');
while (($key, $value) = each (%courses))
{
$value = $courses{$key};
print " $key $value ";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.