This assignment consists of a series of small Perl programs. Don't forget to comment your program, providing a general description of the Perl script along with inline comments for important or complex portions of code.
Problem 1 Data Mining a Dictionary Write Perl scripts that find and print the
following items in a dictionary (dictionary is usually at /usr/dict/words
.
Problem 2 A small mail-order book store uses the price codes and corresponding prices as given below on the left and charges shipping and handling based on the total number of items ordered as indicated below on the right:
Code | Price | Books | Charge | |
CL1 | 12.98 | 1-3 | 3.49 | |
HR1 | 11.98 | 4-6 | 6.49 | |
CL2 | 10.98 | 7-9 | 8.99 | |
SR1 | 11.98 | 10+ | 10.99 | |
SR2 | 14.98 | |||
SR3 | 24.98 |
Store the price information as a hash called %code_to_price
using the price codes as keys and the prices as values. The shipping
and handling charges should be stored in an array. A nested if
structure can be used to select appropriate elements of the array when
calculating shipping and handling.
Write a Perl script book.plx that processes a customer's order. The script should first prompt for a customer's account number. You may assume any account number entered is valid. The program should then display the following menu:
P -- Place a book on order. R -- Remove a book from on order. T -- Total bill and list bookss ordered. E -- Exit. Type choice and hit enter:The script should respond correctly to either a lower or uppercase character. The actions to be taken for each choice are as follows:
%code_to_price
hash. If the corresponding value is
defined, use the book code as a key to a hash called
%purchase
and store the price as a value of
%purchase
. If there is no value in
%code_to_price
for the price code entered, print a
message that an invalid price code was input and do not modify
the %purchase
hash (do not reprompt; display the main
menu again).
%purchase
, print an appropriate message (do not
reprompt); otherwise, delete the location in %purchase
associated with the book code entered
%purchase
(separate them by two tabs)
Purchases for account number M21C: BOOK code Price CL3456 $12.98 CL3367 $10.98 SR2345 $11.98 SR8889 $24.98 Total items on order: 4 Total due (includes shipping and handling): $67.41
The script should continue prompting for choices until an 'E' or 'e' is input by the user.
Recall from the first lecture that in order to run a Perl script, you need to do the following:
#!/usr/local/bin/perl -w
at the beginning of the
script file on a line by itself (assume the file is named
script.plx)
chmod a+x script.plx
script.plx