\documentclass[a4paper]{article}

\usepackage{pslatex}
\renewcommand{\familydefault}{pwm} % bch

\usepackage[pdftex,colorlinks]{hyperref}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{color}
\usepackage{listings}

\input{macros}

\author{Chan Bernard Ki Hong}
\title{Perl 5 Tutorial \\
\normalsize Suggested Answers to Questions}

%\newcommand{\link}[2]{\href{#1}{#2} \\ \textcolor{blue}{#1}}
\setlength{\parindent}{0pt}
\lstset{%
	breaklines=true,%
	tabsize=4,%
	numbers=left,%
	numberstyle=\small,%
	stepnumber=1,%
	linewidth=\linewidth,%
	flexiblecolumns=false,%
	basicstyle=\ttfamily,%
	basewidth=0.5em,%
	numbersep=9pt,%
	prebreak=\P,%
	literate={~}{{$\sim$}}{1}
}

\begin{document}

{\bf
\maketitle
}

\section*{Chapter 5\hspace{1cm}Conditionals, Loops \& Subroutines}

\begin{description}
\item[A.] {The recursive search routine (binarysearch\_recursive.pl) is shown below: \\
\lstinputlisting[backgroundcolor=\color{CodeBackground}]{src/scope/binarysearch_recursive.pl}
}
\end{description}

\section*{Chapter 9\hspace{1cm}Regular Expressions}

\begin{description}
\item[A.] {
	In this case we don't need two critical states. Only one is necessary. Simply set up a loopback transition to itself for
	the input character ``.'' and a transition to the ``Valid'' state for the character ``\mono{\bs w}''. \\

	\image{!hbt}{0.65\textwidth}{!}{images/soln/fsa2.pdf}{FSA diagram of Valid Paths}{fig:fsa2}

	The pattern can thus be represented as \mono{/\^{}((\bs w|\bs .+\bs w)[.\bs w]*\bs /?)+\$/} \\
	which can be further optimized as \mono{/\^{}(((\bs .+)?\bs w)[.\bs w]*\bs /?)+\$/} \\
	and finally \mono{/\^{}(\bs .*\bs w[.\bs w]*\bs /?)+\$/} \\

}
\item[B.] { The code is given below: \\
\lstinputlisting[backgroundcolor=\color{CodeBackground}]{src/files/findcls.pl}
}
\end{description} 



\section*{Chapter 11\hspace{1cm}CGI Programming}

\begin{description}
\item[A.] {
	Given an intruder knows the username of another user (say ``A'') of the shopping cart system, he or she can impersonate
	``A'' by crafting an HTML form with ``A'' as the username to generate orders to which ``A'' has not conceded. This
	is because the script does not try to verify the party submitting the form is indeed ``A''. \\

	With the assumption that the HTML form can only be accepted or declined at this point, the script should verify the 
	list of items to purchase matches exactly the shopping cart of the user as saved in the server database. 
}
\end{description} 


\end{document}
