%% ================================================================================ %% 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{}An Overview of Perl}} \end{center} \begin{center} {\large{}A language for Systems and Network Administration and Management:} \end{center} \begin{center} {\large{}An overview of the language} \end{center} \begin{flushleft} \textbf{{\LARGE{}Where do I get Perl?}} \end{flushleft} \begin{flushleft} {\Large{}For Windows, go to http://www.activestate.com, download the installer} \end{flushleft} \begin{flushleft} {\Large{}For Linux: it will be already installed} \end{flushleft} \begin{flushleft} {\Large{}For other platforms: go to http://www.perl.com} \end{flushleft} \begin{flushleft} {\large{}This is a good source of other information about Perl} \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}Where do I get Info about Perl?}} \end{flushleft} \begin{flushleft} {\footnotesize{}Web sites:} \end{flushleft} \begin{flushleft} {\large{}http://www.perl.com} \end{flushleft} \begin{flushleft} {\large{}http://www.activestate.com} \end{flushleft} \begin{flushleft} {\large{}http://use.perl.org} \end{flushleft} \begin{flushleft} {\footnotesize{}On your hard disk:} \end{flushleft} \begin{flushleft} {\footnotesize{}perldoc --f }\textit{{\footnotesize{}function}} \end{flushleft} \begin{flushleft} {\scriptsize{}Will look up the documentation for the built-in }\textit{{\scriptsize{}function}}{\scriptsize{} (from the documentation perlfunc)} \end{flushleft} \begin{flushleft} {\footnotesize{}perldoc --q }\textit{{\footnotesize{}word}} \end{flushleft} \begin{flushleft} {\scriptsize{}Will look up }\textit{{\scriptsize{}word}}{\scriptsize{} in the headings of the FAQ} \end{flushleft} \begin{flushleft} {\footnotesize{}perldoc perl} \end{flushleft} \begin{flushleft} {\scriptsize{}A list of much of your locally installed documentation, divided into topics} \end{flushleft} \begin{flushleft} {\footnotesize{}ActiveState Perl provides a Programs menu item that links to online html documentation} \end{flushleft} \begin{flushleft} \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}CPAN, PPM: Many Modules}} \end{flushleft} \begin{flushleft} A very strong feature of Perl is the community that supports it \end{flushleft} \begin{flushleft} There are tens of thousands of third party modules for many, many purposes: \end{flushleft} \begin{flushleft} {\footnotesize{}Eg. Net::LDAP module supports all LDAP operations, Net::LWP provides a comprehensive web client} \end{flushleft} \begin{flushleft} Installation is easy: \end{flushleft} \begin{flushleft} \textbf{ sudo perl --MCPAN --e shell} \end{flushleft} \begin{flushleft} \textbf{ install Net::LDAP} \end{flushleft} \begin{flushleft} Will check if a newer version is available on the Internet from CPAN, and if so, download it, compile it, test it, and if it passes tests, install it. \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}PPM: Perl Package Manager}} \end{flushleft} \begin{flushleft} {\large{}For Windows} \end{flushleft} \begin{flushleft} {\large{}Avoids need for a C compiler, other development tools} \end{flushleft} \begin{flushleft} {\large{}Download precompiled modules from ActiveState and other sites, and install them:} \end{flushleft} \begin{flushleft} \textbf{{\large{}ppm install Net::LDAP}} \end{flushleft} \begin{flushleft} {\large{}See documentation with ActiveState Perl} \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}Mailing Lists: help from experts}} \end{flushleft} \begin{flushleft} {\Large{}There are many mailing lists and newsgroups for Perl} \end{flushleft} \begin{flushleft} {\Large{}When subscribe to mailing list, receive all mail from list} \end{flushleft} \begin{flushleft} {\Large{}When send mail to list, all subscribers receive} \end{flushleft} \begin{flushleft} {\Large{}For Windows, many lists at http://www.activestate.com} \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}How to ask Questions on a List}} \end{flushleft} \begin{flushleft} I receive many email questions from students about many topics \end{flushleft} \begin{flushleft} Most questions are not clear enough to be able to answer in any way except, ``please tell me more about your problem'' \end{flushleft} \begin{flushleft} Such questions sent to mailing lists are often unanswered \end{flushleft} \begin{flushleft} Need to be concise, accurate, and clear \end{flushleft} \begin{flushleft} {\footnotesize{}see also Eric Raymond's }\textit{{\footnotesize{}How to Ask Questions the Smart Way}}{\footnotesize{} at }{\large{}http://catb.org/\~{}esr/faqs/smart-questions.html}{\footnotesize{} } \end{flushleft} \begin{flushleft} Search the FAQs first \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}Where is Perl on my system?}} \end{flushleft} \begin{flushleft} {\Large{}ActiveState Perl installs }\textbf{{\Large{}perl.exe}}{\Large{} in }\textbf{{\Large{}C:\ensuremath{\backslash}Perl\ensuremath{\backslash}perl.exe}} \end{flushleft} \begin{flushleft} {\Large{}Linux systems have a standard location for perl at }\textbf{{\Large{}/usr/bin/perl}} \end{flushleft} \begin{flushleft} {\Large{}On some UNIX systems, it may be installed at }\textbf{{\Large{}/usr/local/bin/perl}} \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}How does my OS know it's a Perl program?}} \end{flushleft} \begin{flushleft} {\footnotesize{}To run your Perl program, OS needs to call perl} \end{flushleft} \begin{flushleft} {\footnotesize{}How does OS know when to call Perl?} \end{flushleft} \begin{flushleft} {\footnotesize{}Windows:} \end{flushleft} \begin{flushleft} {\footnotesize{}OS uses the extension of the file to decide what to do (e.g., }\textbf{{\footnotesize{}.bat}}{\footnotesize{}, }\textbf{{\footnotesize{}.exe}}{\footnotesize{})} \end{flushleft} \begin{flushleft} {\footnotesize{}Your program names end with }\textbf{{\footnotesize{}.pl}} \end{flushleft} \begin{flushleft} {\footnotesize{}Linux, Unix:} \end{flushleft} \begin{flushleft} {\footnotesize{}programs have }\textit{{\footnotesize{}execute}}{\footnotesize{} permission (}\textbf{{\footnotesize{}chmod +x }}\textbf{\textit{{\footnotesize{}program}}}{\footnotesize{})} \end{flushleft} \begin{flushleft} {\footnotesize{}OS reads first 2 bytes of program: if they are ``}\textbf{{\footnotesize{}\#!}}{\footnotesize{}'' then read to end of line, then use that as the interpreter} \end{flushleft} \begin{flushleft} {\footnotesize{}OS doesn't care what your program file is called} \end{flushleft} \begin{flushleft} {\footnotesize{}For cross platform support:} \end{flushleft} \begin{flushleft} {\footnotesize{}Put this at the top of all your programs:} \end{flushleft} \begin{flushleft} \textbf{{\footnotesize{}\#! /usr/bin/perl --w}} \end{flushleft} \begin{flushleft} {\footnotesize{}Name your programs with an extension }\textbf{{\footnotesize{}.pl}} \end{flushleft} \begin{flushleft} \end{flushleft} \begin{center} \textbf{{\LARGE{}Language Overview}} \end{center} \begin{center} {\large{}A quick look at more important features of the language} \end{center} \begin{flushleft} \textbf{{\LARGE{}Funny Characters \$, @, \%}} \end{flushleft} \begin{flushleft} Variables in Perl start with a \textit{funny character} \end{flushleft} \begin{flushleft} Why? \end{flushleft} \begin{flushleft} No problem with reserved words: \end{flushleft} \begin{flushleft} {\footnotesize{}can have a variable called \$while, and another variable called @while, and a third called \%while.} \end{flushleft} \begin{flushleft} Can \textit{interpolate} value into a string: \end{flushleft} \begin{flushleft} \textbf{{\footnotesize{}my \$string = ``long'';}} \end{flushleft} \begin{flushleft} \textbf{{\footnotesize{}my \$number = 42.42;}} \end{flushleft} \begin{flushleft} \textbf{{\footnotesize{}print ``my string is \$string and my number is \$number\ensuremath{\backslash}n'';}} \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}Arrays}} \end{flushleft} \begin{flushleft} Define an array like this: \end{flushleft} \begin{flushleft} my @array = ( 1, 5, ``fifteen'' ); \end{flushleft} \begin{flushleft} This is an array containing three elements \end{flushleft} \begin{flushleft} The first can be accessed as \$array[0], second as \$array[1], the last as \$array[2] \end{flushleft} \begin{flushleft} Note that since each element is a scalar, it has the \$ funny character for a scalar variable \textit{value} \end{flushleft} \begin{flushleft} In Perl, we seldom use an array with an index---use list processing array operations \end{flushleft} \begin{flushleft} {\footnotesize{}higher level.} \end{flushleft} \begin{flushleft} \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}Hashes}} \end{flushleft} \begin{flushleft} Hashes are probably new to you \end{flushleft} \begin{flushleft} Like an array, but indexed by a string \end{flushleft} \begin{flushleft} Similar idea was implemented in java.lang.HashTable \end{flushleft} \begin{flushleft} {\footnotesize{}Perl hashes are easier to use} \end{flushleft} \begin{flushleft} Example: \end{flushleft} \begin{flushleft} \textbf{my \%hash = ( NL => 'Netherlands',} \end{flushleft} \begin{flushleft} \textbf{ BE => 'Belgium' );} \end{flushleft} \begin{flushleft} This creates a hash with two elements \end{flushleft} \begin{flushleft} first is \$hash\{NL\}, has value ``Netherlands''; \end{flushleft} \begin{flushleft} second is \$hash\{BE\} with value "Belgium" \end{flushleft} \begin{flushleft} \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}String Operations}} \end{flushleft} \begin{flushleft} Perl has all the operators from C, in same precedence \end{flushleft} \begin{flushleft} Has more operators for strings: \end{flushleft} \begin{flushleft} Join strings with a dot, e.g. \end{flushleft} \begin{flushleft} \textbf{{\footnotesize{} print "The sum of 3 and 4 is " . 3 + 4 . "\ensuremath{\backslash}n";}} \end{flushleft} \begin{flushleft} Quote special characters with a backslash, as in C \end{flushleft} \begin{flushleft} \textbf{ print "\ensuremath{\backslash}\$value = \$value\ensuremath{\backslash}n";} \end{flushleft} \begin{flushleft} Can quote all characters using single quotes: \end{flushleft} \begin{flushleft} \textbf{{\scriptsize{} print 'output of \$perl = "rapid";print \$perl; is "rapid"';}} \end{flushleft} \begin{flushleft} Note that double quotes are okay in single quotes, single quotes okay in double quotes. \end{flushleft} \begin{flushleft} \end{flushleft} \begin{flushleft} \textbf{{\LARGE{}See the perl summary}} \end{flushleft} \begin{flushleft} {\Large{}The Perl summary on the subject web site provides\ldotswell, a good summary!} \end{flushleft} \begin{flushleft} \end{flushleft} \end{document}