%% ================================================================================
%% This LaTeX file was created by AbiWord.                                         
%% AbiWord is a free, Open Source word processor.                                  
%% You may obtain more information about AbiWord at www.abisource.com              
%% ================================================================================

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{calc}
\usepackage{hyperref}\usepackage{setspace}
\usepackage{multicol}
\usepackage[normalem]{ulem}
\usepackage{color}
 
\setlength{\oddsidemargin}{1.250000in-1in}
\setlength{\textwidth}{\paperwidth - 1.250000in-1.250000in}


\begin{document}
\begin{center}
\textbf{{\LARGE{}Perl}}
\end{center}

\begin{center}
{\large{}A language for Systems and Network Administration and Management}
\end{center}

\begin{flushleft}
\textbf{{\LARGE{}What is Perl?}}
\end{flushleft}

\begin{flushleft}
{\large{}Perl is a programming language}
\end{flushleft}

\begin{flushleft}
{\large{}The best language for processing text}
\end{flushleft}

\begin{flushleft}
{\large{}Cross platform, free, open}
\end{flushleft}

\begin{flushleft}
{\large{}Microsoft have invested heavily in ActiveState to improve support for Windows in Perl}
\end{flushleft}

\begin{flushleft}
{\large{}Has excellent connection to the operating system}
\end{flushleft}

\begin{flushleft}
{\large{}Has enormous range of modules for thousands of application types}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}What is Perl?				2}}
\end{flushleft}

\begin{flushleft}
Robust and reliable (has very few bugs)
\end{flushleft}

\begin{flushleft}
Supports object oriented programming
\end{flushleft}

\begin{flushleft}
Good for big projects as well as small
\end{flushleft}

\begin{flushleft}
Java 1.4 has borrowed one of Perl's best features: \textit{regular expressions}
\end{flushleft}

\begin{flushleft}
Perl has garbage collection
\end{flushleft}

\begin{flushleft}
The ``duct tape of the Internet''
\end{flushleft}

\begin{flushleft}
Easy to use, since it usually ``does the right thing''
\end{flushleft}

\begin{flushleft}
Based on freedom of choice: ``There is more than one way to do it!''
\end{flushleft}

\begin{flushleft}
TIMTOWTDI
\end{flushleft}

\begin{flushleft}

\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Compiled and run each time}}
\end{flushleft}

\begin{flushleft}
{\large{}Perl is interpreted, but runs about as fast as a Java program}
\end{flushleft}

\begin{flushleft}
{\large{}Software development is very fast}
\end{flushleft}

\begin{flushleft}
{\large{}The Apache web server provides mod\_perl, allows Perl applications to run very fast}
\end{flushleft}

\begin{flushleft}
{\large{}Used on some very large Internet sites:}
\end{flushleft}

\begin{flushleft}
The Internet Move Database
\end{flushleft}

\begin{flushleft}
Macromedia, Adobe, http://slashdot.org/
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Perl is Evolving}}
\end{flushleft}

\begin{flushleft}
{\Large{}Perl 6 will introduce many great features to make Perl}
\end{flushleft}

\begin{flushleft}
{\large{}easier to use}
\end{flushleft}

\begin{flushleft}
{\large{}Even more widely usable for more purposes}
\end{flushleft}

\begin{flushleft}
{\large{}Even better for bigger projects}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Eclectic}}
\end{flushleft}

\begin{flushleft}
{\Large{}Borrows ideas from many languages, including:}
\end{flushleft}

\begin{flushleft}
{\large{}C, C++}
\end{flushleft}

\begin{flushleft}
{\large{}Shell}
\end{flushleft}

\begin{flushleft}
{\large{}Lisp}
\end{flushleft}

\begin{flushleft}
{\large{}BASIC}
\end{flushleft}

\begin{flushleft}
{\large{}\ldotseven Fortran}
\end{flushleft}

\begin{flushleft}
{\large{}Many others\ldots}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Regular Expressions}}
\end{flushleft}

\begin{flushleft}
{\Large{}One of the best features of Perl}
\end{flushleft}

\begin{flushleft}
{\Large{}A new concept for most of you}
\end{flushleft}

\begin{flushleft}
{\Large{}\ldotsBut very useful!}
\end{flushleft}

\begin{flushleft}
{\Large{}Used to:}
\end{flushleft}

\begin{flushleft}
{\large{}extract information from text}
\end{flushleft}

\begin{flushleft}
{\large{}transform information}
\end{flushleft}

\begin{flushleft}
{\Large{}You will spend much time in this topic learning about regular expressions}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Why should I learn it?}}
\end{flushleft}

\begin{flushleft}
It will be in the final exam!
\end{flushleft}

\begin{flushleft}
{\footnotesize{}Okay, that's to get your attention, but\ldots}
\end{flushleft}

\begin{flushleft}
\textbf{{\Large{}Consider a real-life sys-admin problem:}}
\end{flushleft}

\begin{flushleft}
{\footnotesize{}You must make student accounts for 1500 students}
\end{flushleft}

\begin{flushleft}
{\footnotesize{}TEACHING BEGINS TOMORROW!!!}
\end{flushleft}

\begin{flushleft}
{\footnotesize{}The Computing Division has a multi-million dollar application to give you student enrollment data}
\end{flushleft}

\begin{flushleft}
{\footnotesize{}\ldotsbut it can only give you PDF files with a strange and irregular format for now (But Oh, it will be infinitely better in the future!  Just wait a year or two\ldots)}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}The available data}}
\end{flushleft}

\begin{flushleft}
{\large{}Has a variable number of lines before the student data begins}
\end{flushleft}

\begin{flushleft}
{\large{}Has a variable number of columns between different files}
\end{flushleft}

\begin{flushleft}
{\large{}Has many rows per enrolled student}
\end{flushleft}

\begin{flushleft}
{\large{}Goes on for dozens of pages, only 7 students per page!!!!!!!}
\end{flushleft}

\begin{flushleft}
{\large{}There are two formats, both equally peculiar!!!!}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Sample data for new courses:}}
\end{flushleft}

\begin{flushleft}
{\Large{} }{\scriptsize{}15    N    CHAN Wai Yee                     F 993175560     H123456(5)                        28210216              CHEUNG}
\end{flushleft}

\begin{flushleft}
{\scriptsize{}                  10-SEP-01         10-SEP-01                    21234567                                                 WAI CHI                                                                                                                      SISTER                                                                                                       91234567}
\end{flushleft}

\begin{flushleft}

\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Problems}}
\end{flushleft}

\begin{flushleft}
{\large{}There is a different number of lines above the student records}
\end{flushleft}

\begin{flushleft}
{\large{}There is a different number of characters within each column from file to file}
\end{flushleft}

\begin{flushleft}
{\large{}There are many files}
\end{flushleft}

\begin{flushleft}
{\large{}The format can change any time the computing division determines necessary}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Solution in Perl}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}\#! /usr/bin/perl -w}}
\end{flushleft}

\begin{flushleft}

\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}use strict;}}
\end{flushleft}

\begin{flushleft}

\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}my \$course;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}my \$year;}}
\end{flushleft}

\begin{flushleft}

\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}while ( <> )}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}\{}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    chomp;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    }}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    if ( /\^{}\ensuremath{\backslash}s*Course :\ensuremath{\backslash}s(\ensuremath{\backslash}d+)\ensuremath{\backslash}s/ )}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    \{}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        \$course = \$1;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        undef \$year;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        next;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    \}}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    elsif ( m!\^{}\ensuremath{\backslash}s*Course :\ensuremath{\backslash}s(\ensuremath{\backslash}d+)/(\ensuremath{\backslash}d)\ensuremath{\backslash}s! )}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    \{}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        \$course = \$1;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        \$year = \$2;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        next;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    \}}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    if (}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        my ( \$name, \$gender, \$student\_id, \$hk\_id )}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}         \#= m!\ensuremath{\backslash}s\ensuremath{\backslash}s+([A-Z]+(?: [A-Z][a-z]*)+)\ensuremath{\backslash}s\ensuremath{\backslash}s+([MF])\ensuremath{\backslash}s+(\ensuremath{\backslash}d\{9\})\ensuremath{\backslash}s\ensuremath{\backslash}s+([a-zA-Z]\ensuremath{\backslash}d\{6\}\ensuremath{\backslash}([\ensuremath{\backslash}dA-Z]\ensuremath{\backslash}))! )}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}         = m\{}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                 \ensuremath{\backslash}s\ensuremath{\backslash}s+                      \# at leaset 2 spaces}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                 (                          \# this matches \$name}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                     [A-Z]+                 \# family name is upper case}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                     (?:\ensuremath{\backslash}s[A-Z][a-z]*)+     \# one or more given names}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                 )}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                 \ensuremath{\backslash}s\ensuremath{\backslash}s+                      \# at leaset 2 spaces}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                 ([MF])                     \# gender}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                 \ensuremath{\backslash}s+                        \# at least one space}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                 (\ensuremath{\backslash}d\{9\})                    \# student id is 9 digits}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                 \ensuremath{\backslash}s\ensuremath{\backslash}s+                      \# at leaset 2 spaces}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}                 ([a-zA-Z]\ensuremath{\backslash}d\{6\}\ensuremath{\backslash}([\ensuremath{\backslash}dA-Z]\ensuremath{\backslash})) \# HK ID}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}            \}x}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}       )}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    \{}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        print "sex=\$gender, student ID = \$student\_id, ",}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        "hkID = \$hk\_id, course = \$course, name=\$name, ",}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        defined \$year ? "year = \$year\ensuremath{\backslash}n" : "\ensuremath{\backslash}n";}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}        next;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    \}}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}    warn "POSSIBLE UNMATCHED STUDENT: \$\_\ensuremath{\backslash}n" if m!\^{}\ensuremath{\backslash}s*\ensuremath{\backslash}d+\ensuremath{\backslash}s+!;}}
\end{flushleft}

\begin{flushleft}
\textbf{{\tiny{}\}}}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}But I can use any other language!}}
\end{flushleft}

\begin{flushleft}
I will give you HK\$200 if you are the first person to write a solution in another language in fewer keystrokes
\end{flushleft}

\begin{flushleft}
Note: the Perl solution given has:
\end{flushleft}

\begin{flushleft}
{\footnotesize{}comments}
\end{flushleft}

\begin{flushleft}
{\footnotesize{}Plenty of space to show structure}
\end{flushleft}

\begin{flushleft}
{\footnotesize{}\ldotsand handles exceptional situations (i.e., it is robust)}
\end{flushleft}

\begin{flushleft}
To claim your \$200 from Nick, your solution must have
\end{flushleft}

\begin{flushleft}
{\footnotesize{}similar space for comments}
\end{flushleft}

\begin{flushleft}
{\footnotesize{}Similar readability and robustness}
\end{flushleft}

\begin{flushleft}
{\footnotesize{}Be written in a general purpose language using ordinary libraries}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Any other solution may take longer to write }}
\end{flushleft}

\begin{flushleft}
{\Large{}This program took a very short time to write}
\end{flushleft}

\begin{flushleft}
{\Large{}It is very robust}
\end{flushleft}

\begin{flushleft}
{\Large{}For problems like this, Perl is second to no other programming language.}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}The hello world program}}
\end{flushleft}

\begin{flushleft}
{\Large{}print ``hello world\ensuremath{\backslash}n''}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Variables}}
\end{flushleft}

\begin{flushleft}
{\large{}There are three basic types of variable:}
\end{flushleft}

\begin{flushleft}
\textbf{\textit{{\large{}Scalar}}}{\large{} (can be a number or string or\ldots)}
\end{flushleft}

\begin{flushleft}
\textbf{\textit{{\large{}Array}}}{\large{} (an ordered array of scalars)}
\end{flushleft}

\begin{flushleft}
\textbf{\textit{{\large{}Hash}}}{\large{} (an unordered array of scalars indexed by strings instead of numbers)}
\end{flushleft}

\begin{flushleft}
{\large{}Each type distinguished with a ``funny character''}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}\$Scalars:}}
\end{flushleft}

\begin{flushleft}
{\Large{}Start with a dollar sign}
\end{flushleft}

\begin{flushleft}
{\Large{}Hold a single value, not a collection}
\end{flushleft}

\begin{flushleft}
{\Large{}A string is a scalar, so is a number}
\end{flushleft}

\begin{flushleft}
{\Large{}Examples:}
\end{flushleft}

\begin{flushleft}
{\Large{}\$apple = 2;}
\end{flushleft}

\begin{flushleft}
{\Large{}\$banana = ``curly yellow fruit'';}
\end{flushleft}

\begin{flushleft}

\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}@Array}}
\end{flushleft}

\begin{flushleft}
{\Large{}Starts with a @}
\end{flushleft}

\begin{flushleft}
{\Large{}Indexes start at 0, like in C}
\end{flushleft}

\begin{flushleft}

\end{flushleft}

\begin{flushleft}

\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}\%Hashes}}
\end{flushleft}

\begin{flushleft}
{\Large{}Unfamiliar concept to many of you}
\end{flushleft}

\begin{flushleft}
{\Large{}Like an array, but indexed by a string}
\end{flushleft}

\begin{flushleft}
{\Large{}A data structure like a database}
\end{flushleft}

\begin{flushleft}
\textbf{{\LARGE{}Conclusion}}
\end{flushleft}

\begin{flushleft}
{\Large{}Perl is optimised for text and systems administration programming}
\end{flushleft}

\begin{flushleft}
{\Large{}Has great portability}
\end{flushleft}

\begin{flushleft}
{\Large{}Is strongly supported by Microsoft}
\end{flushleft}

\begin{flushleft}
{\Large{}Has three main built-in data types:}
\end{flushleft}

\begin{flushleft}
{\large{}Scalar: starts with \$}
\end{flushleft}

\begin{flushleft}
{\large{}Array: starts with @}
\end{flushleft}

\begin{flushleft}
{\large{}Hash: starts with \%}
\end{flushleft}

\begin{flushleft}

\end{flushleft}

\end{document}
