Need help with Perl!
I am currently learning how to use Perl from a book. One of the exercises on chapter 4 (Scalars, Arrays and Hashes) has really left me dumb. This is the problem, but I can't figure out the coding to make the "Course code" typed in the user to appear in the place of "Shell Programming" where it should be.
HELP!
Exercise:
Write a script called elective that will contain a hash.
a. The keys will be code numbers --2CPR2B, 1UNX1B, 3SH414, 4PL400.
b. The values will be course names, C Language, Intro to UNIX, Shell Programming, Perl Programming.
c. PRint the entire array.
d. Ask the user to type the code number for the course he plans to take this semester and print a line resembling the following:
You will be taking Shell Programming this semester.
Here is the coding I have so far:
#! Usr/bin/perl
%courses = (
'2CPR2B' => 'C Programming',
'1UNX1B' => 'Intro to UNIX',
'4PL400' => 'Perl Programming',
'3SH414' => 'Shell Programming',
);
print %courses, "\n";
print "Please type in the code number of the course you will be taking this semester:", "\n";
$course=<STDIN>;
print "You will be taking $courses{$course} this semester.\n";
|