This assignment consists of a series of small Perl programs. It should be submitted according to the Submission Guidelines. 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.
$x
is a variable holding a floating-point value, it may be
truncated to an integer value using the Perl builtin function
int
(that is, int($x)
). Once all data have been input, the
histogram should be printed. Histogram intervals should be output
one to a line. Each line should begin with the interval number,
followed by a space, a colon, and another space. An asterisk
(*
) should be printed for each value falling in an interval.
Thus, if the array indicates that the zeroth interval contains 6
values, 0 : ******
should be printed as the first line. Given a
file integers.dat with one number to a line (and -1 as
the last value), the script may be run as histogram.plx <
integers.dat.
Code | Price | CDs | 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 cd.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 CD on order. R -- Remove a CD from on order. T -- Total bill and list CDs 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 cd 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 cd code entered
%purchase
(separate them by two tabs)
Purchases for account number M21C: CD 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