170 likes | 293 Views
Introducing System Managers to Win32 Perl Programming. Tim Christian (tim@unt.edu) College of Arts and Sciences Computing Support Services. Welcome! This course:. is for people who know some other programming language and
E N D
Introducing System Managers to Win32 Perl Programming Tim Christian (tim@unt.edu) College of Arts and Sciences Computing Support Services
Welcome! This course: • is for people who know some other programming language and • should enable you to manage the network, write reports, and write CGI scripts using Perl.
Course Outline • About Perl • Installing Perl • Writing Perl • Debugging Perl • Extending Perl • Applying Perl Using Regular Expressions • Applying Perl for CGI
About Perl • Larry Wall • If you were to write a language that anybody could use, what would be some characteristics of that language?
Installing Perl • Normally, from: www.activestate.com • For a limited time from www.cascss.unt.edu/~tim/perl/ • After installing Perl, how do you get help? • Your personal task before next class: Install Perl on your computer at work and/or home.
Writing Perl • Comments • Statements • Programs • Data Types • Data Type Operators • Flow Control • File Operators
Comments • First line comments, like: #!/usr/bin/perl • Other Comments • Example: www.cascss.unt.edu/~tim/perl/comment.pl
Statements • Every part of a Perl script (except comments) consists of a statement. • Contain one or more function calls, L/Rvalues, and flow controls. • End with a semicolon (;). • Perl ignores all white space. • Example: www.cascss.unt.edu/~tim/perl/statement.pl
Programs • Running from the command line. • Running from a file. • Example: www.cascss.unt.edu/~tim/perl/birth.pl
Data Types • Scalars: www.cascss.unt.edu/~tim/perl/scalar.pl • Arrays: www.cascss.unt.edu/~tim/perl/array.pl • Associative arrays: www.cascss.unt.edu/~tim/perl/assocarray.pl • The $_ and @_ variables.
Data Types Comparators • To compare characters: eq, ne, lt, gt, le, ge • To compare numbers: ==, !=, <. >, <=, >= • Mnemonic: Always use characters to compare characters. • More: www.perl.com/CPAN-local/doc/manual/html/pod/perlop.html
Flow Control • If/else: www.cas.unt.edu/~tim/perl/if.pl • For: www.cas.unt.edu/~tim/perl/for.pl • Foreach: www.cas.unt.edu/~tim/perl/foreach.pl • Subroutines: www.cas.unt.edu/~tim/perl/subroutine.pl
File Operators • Special <> notation for the identifier. • Useful functions: open, close • Uses redirection symbols: >, <, >>, <<, | • Example: www.cas.unt.edu/~tim/perl/file.pl
Debugging Perl • What is a debugger? • What is the best debugger? • Perl’s -d switch.
Extending Perl • Functions: www.perl.com/CPAN-local/doc/manual/html/pod/perlfunc.html • Modules: www.cpan.org/ • Getting help with modules. • Using Modules.
Account Builder • Use flow control and subroutines and good coding style to: • Read in a file of names (like “Tim Christian”). • Create 8 character IDs based on those names until ID@unt.edu does not exist. • Hint: You might want to check out the length() and substr() functions.
Next Class • Bring your account builder solution to class • Regular expressions • Applying regular expressions in Perl