Complete the following tasks: (25 pts.) a) Write a script to create a hash list
ID: 3714464 • Letter: C
Question
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). 1) b) Print 3 of states by accessing their keys c 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) 2Write a seript 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.)Explanation / Answer
#!/usr/bin/perl
#(QUESTION 1)
# (a) Create a HASH list of 10 states
%states = ('GA'=>'Georgia', 'NJ'=>'New Jersey' , 'CA'=>'California','NY'=>'New York','VT'=>'Vermont',
'WA'=>'Washington','PA'=>'Pennsylvania','MD'=>'Maryland','CO'=>'Colorado','IL'=>'Illinois');
# (b) print 3 states by accessing their key
print "$states{'GA'} ";
print "$states{'NJ'} ";
print "$states{'VT'} ";
# (c) Replace tyhe velue of three states
$states{'GA'} = 'Georgia USA';
$states{'CO'} = 'Colorado USA';
$states{'IL'} = 'Illinois USA';
# (d) remove three states
delete $states{'PA'};
delete $states{'NY'};
delete $states{'NJ'};
# (e) print HASH LIST IN TABULAR USING LOOP
@code = keys %states;
@state = values %states;
$count=keys %states;
print "City Code | City Name ";
for($i=0 ; $i < $count ; $i=$i+1)
{
print "$code[$i] $state[$i] ";
}
print " ";
#(2)
%subjects = ('CS101'=>'COMPUTER SCIENCE','MAT102'=> 'MATHEMATICS','PHY103' =>'PHYSICS','HIS203'=>'HISTORY' , 'ROB301'=>'ROBOTICS');
$count = keys %subjects;
@subCode = keys %subjects;
@subject = values %subjects;
print "COURSE ABBR. | COURSE DISCRIPTION ";
for($i=0 ; $i <$count ; $i=$i+1)
{
print "$subCode[$i] $subject[$i] ";
}