\documentstyle[11pt]{article}
\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\marginparwidth}{0pt}
\setlength{\marginparsep}{0pt}
\setlength{\topmargin}{-40pt}
\setlength{\textwidth}{470pt}
\setlength{\textheight}{650pt}

\newcommand{\ret}{\framebox{\tiny RETURN}}
\newcommand{\ctrld}{\framebox{\tiny Ctrl-D}}
\newcommand{\ctrlc}{\framebox{\tiny Ctrl-C}}
\newcommand{\bl}{\hspace{16pt}}
\newcommand{\bitem}{\begin{itemize} \setlength{\itemsep}{0pt}}
\newcommand{\eitem}{\end{itemize}}
\newcommand{\benum}{\begin{enumerate} \setlength{\itemsep}{0pt}}
\newcommand{\eenum}{\end{enumerate}}

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
{\bf
\hrule
\ \\
{\em Fall 97 - Programming in Perl} \\
Perl TEST - November 5, 1997\\
{\em Instructor: Louis Ziantz} \\
\vspace{5pt} 
\hrule
}
\end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\thispagestyle{empty}

\vspace{1.5in}
\begin{verbatim}

                    Question 1  [20 pts] : _______________

                    Question 2  [25 pts] : _______________

                    Question 3  [30 pts] : _______________

                    Question 4  [25 pts] : _______________

                    Total Score [100pts] : _______________ 
\end{verbatim}
\vspace{1.0in}
Read each question carefully and make sure to {\bf show all of your work}.
\begin{flushleft}

\vspace{1in}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Your name:\underline{\hspace{3.0in}} \\ 
\vspace{0.25in}
Your RCS userid:\underline{\hspace{2.0in}} \\
\vspace{0.25in}
Have you ever used HTML to create a webpage? \underline{\hspace{1.0in}}
\vspace{0.2in}

\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{enumerate}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%\item [$\,$] {\bf Question 1} {\em [  pts]} \\
%%Suppose we placed the following Perl code in a file called
%%\underline{hello.pl} (it is the ONLY thing in the file):
%%\begin{verbatim}
%%print ("Hello world\n");
%%\end{verbatim}

%%We can execute the \underline{hello.pl} script by typing \verb+perl
%%hello.pl+ at a UNIX command prompt.  Starting with the contents of
%%\underline{hello.pl}, how else can we get the Perl script to run?
%%There are three steps:
%%\begin{enumerate}
%%  \item $\,$
%%  \vspace{1.5in}
  

%%  \item $\,$
%%  \vspace{1.5in}

%%  \item $\,$
%%  \vspace{1in}

%%\end{enumerate}

%%\newpage
\item [$\,$] {\bf Question 1} {\em [20 pts]} \\ 

In the space provided below, indicate what the following snippet of
Perl code prints (represent a newline by {\em $<$n$>$} and assume that
the \verb+-w+ flag is not used so no warnings will be printed):
\begin{verbatim}
$a1 = 1;
$var1 = "15th " + "St" . "8th " . "St";
$var2 = 2;
$var3 = "N = " . 13 x $var2;
$var4 = 'camel\n';
chomp($var4);
$var5 = chop($var4);
@a1 = (1, 2, 3, 4);
@a2 = reverse(@a1);
($var6, $var7, $var8) = @a2[0,1];

print ( "$var1\n" ); # 1
print ( "$var2\n" ); # 2
print ( "$var3\n" ); # 3
print ( "$var4\n" ); # 4
print ( "$var5\n" ); # 5
print ( "$var6\n" ); # 6
print ( "$var7\n" ); # 7
print ( "$var8\n" ); # 8
print ( "$a1[$a2[$#a1]]\n" ); # 9
print ( "${a1}[$a2[-2]]\n" ); # 10
\end{verbatim}

\begin{flushleft}
1) \underline{\hspace{5in}} \\
\vspace{0.2in}
2) \underline{\hspace{5in}} \\
\vspace{0.2in}
3) \underline{\hspace{5in}} \\
\vspace{0.2in}
4) \underline{\hspace{5in}} \\
\vspace{0.2in}
5) \underline{\hspace{5in}} \\
\vspace{0.2in}
6) \underline{\hspace{5in}} \\
\vspace{0.2in}
7) \underline{\hspace{5in}} \\
\vspace{0.2in}
8) \underline{\hspace{5in}} \\
\vspace{0.2in}
9) \underline{\hspace{5in}} \\
\vspace{0.2in}
10) \underline{\hspace{5in}} \\
\end{flushleft}

\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item [$\,$] {\bf Question 2} {\em [25 pts]} \\ 

Read a series of numeric class grades from standard input into an
array (assume one grade per line).  You may assume all data entered is
valid.  After the values have been input, determine the number of A's,
B's, C's, and F's based on the following scale:
\begin{center}
\begin{tabular}{|c|c|} \hline
Score    & Grade \\ \hline
90--100  &  A  \\ \hline
80--89   &  B  \\ \hline
70--79   &  C  \\ \hline
0--69    &  F  \\ \hline
\end{tabular}
\end{center}
You should also compute the average grade for the class.  Print the
class average, the number of A's, the number of B's, the number of
C's, and the number of F's.  Each piece of information should be
printed on a separate line with appropriate text labels, e.g., 
\vspace{-0.2in}
\begin{verbatim}
Class average : 75<newline>
Number of A's: 20<newline>
(and so forth)
\end{verbatim}




\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item [$\,$] {\bf Question 3} {\em [30 pts]} \\ 
Given the following arrays:
\begin{verbatim}
@day_nums = (1, 2, 3, 4, 5, 6, 7); 
@day_strings = ('mon.', 'tue.', 'wed.', 'thur.', 'fri.', 'sat.', 'sun.');
\end{verbatim}

\begin{enumerate}

  \item Assign the same values as in the first assignment above to
  \verb+@day_nums+ using the list constructor operator (\verb+..+).  
  \vspace{1in}

  \item Assign the same values as in the second assignment above to
  \verb+@day_strings+ without explicitly using either single or double
  quotes around the strings.  
  \vspace{1in}

\end{enumerate}

Given the following hash:
\begin{verbatim}
%days = (1, 'mon.', 2, 'tue.', 3, 'wed.', 4, 'thur.', 
         5, 'fri.', 6, 'sat.', 7, 'sun.');
\end{verbatim}

\begin{enumerate}
  \item[(c)] Use the arrays \verb+@day_nums+ and \verb+@day_strings+ to
  create a hash \verb+%days1+ having the same key-value pairs as
  \verb+%days+. 
  \vspace{1in}

  \item[(d)] Create a hash \verb+%days2+ having the same key-value pairs
  as
  \verb+%days+ using the \verb+=>+ operator and literals.
  \vspace{3in}

\newpage

  \item[(e)] Use the \verb+foreach+ control structure along with any
  built-in functions needed to print the values of the hash
  \verb+%days+ on separate lines.  
  \vspace{2in}
 
  \item[(f)] Iterate through the hash \verb+%days+ using the \verb+each+
  function and print the values of the hash on separate lines with the
  first letter of each day capitalized.  
  \vspace{2in}

\end{enumerate}

\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item [$\,$] {\bf Question 4}{\em [25 pts]} \\ 

Use the diamond operator to write a Perl script that functions as a
simple \verb+more+ command.  If a user types \verb+more.pl file1+, the
script should print the first \verb+$max_num_lines+ (say 20) lines of
\underline{file1} and then prompt the user for input from standard
input as follows:
\begin{verbatim}
(lines from file1)
Action [l or p]:
\end{verbatim}
The script should continue prompting for and reading the
\verb+$action+ until an \verb+l+ followed by a return or a \verb+p+
followed by a return is typed.  If an \verb+l+ is entered, the script
should print the next line of the file and prompt again for an action.
If a \verb+p+ is input, the script should print the next
\verb+$max_num_lines+ lines of \underline{file1} before prompting for
an action again.  This process (prompting and printing either the next
line or the next \verb+$max_num_lines+ lines) should continue until
the file's contents are exhausted.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% \item {\bf Question 6 } {\em [5pts]} \\ 

%% Consider the classes of Questions 3 and 5.  Is using {\em
%% default memberwise copy} sufficient for both classes or would the
%% assignment operator ({\tt =}) have to be overloaded for one or both of
%% them?  Please specify which, if any, of the classes would require this
%% to be done and the reason why?  You do {\bf not} have to actually
%% write code to overload the operator.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{enumerate}
\end{flushleft}
\end{document}

