Computer Science @ Marlboro  

Introduction to Programming with Perl

Info | Syllabus | Assignments | Lecture Notes | Resources | Roster

Info
 
WhenTues/Thur 1:00-11:20
WhereSci 217
FacultyJim Mahoney (mahoney@marlboro.edu)
Text Elements of Programming with Perl by Andrew Johnson Errata
Credits 4 ( i.e. 9 hours/week outside class )
Level Introductory
Prereq some familiarity with computers
Website http://cs.marlboro.edu/term/fall03/Perl.html

An exploration of the basic ideas behind programming, including function calls, input / output, and data structures. Perl is a modern programming language suitable to a wide variety of tasks, including dynamic www sites. Besides, it's fun. Recommended for students planning on work in computer science. Prerequisite: Familiarity with computers.
Grading will be based on weekly assignments, one exam early in the semester, two small programming projects along the way, and a final project of your choosing. All the projects will be graded based on both the code and documentation. I'll drop the lowest of these five grades and average the rest.

Assignments and resources will be added to this webpage throughout the semester.


Assignments
  1. for Tues Sep 9
    1. Read Neal Stephenson's article In the Beginning was the Command Line
    2. Read at least chapter 1 in the text.
    3. Visit the monastry and browse around.
    4. If your existing expertise allows, try to follow the instructions in chapter 1 to enter and run "Hello World" program. I'll talk in class about how to do this in several ways: on our campus server (akbar), on a lab PC or Mac, or on your own computer. There are some links at the bottom of this page to Perl and some editors which may help. (Don't worry if this doesn't come together yet; it will.)
    5. Send me (mahoney@marlboro.edu)) an email that says
      1. that you're in this class,
      2. how successful you were with "Hello World",
      3. what kind of computers you've used (windows, mac, linux, ...)
      4. what sorts of things can you already do on a computer.

  2. for Tues Sep 16
    1. Finish reading chapters 2 and 3 in the text.
    2. Type in (or find online) the mathq program described in chapter 3. Run it. Add some print statements to see what it's doing.
    3. Modify that program, either as you see fit or following the exercises at the end of chapter 3. Comment what you've done. Send me the result, including a sample of what it looks like when it runs.
    4. Start in on chapter 4 in the text; I'll be talking about that next Tuesday.

  3. for Tues Sep 23
    1. Read chapters 4 (data types) and 5 (control structures).
    2. Do exercises 1 and 2 at the end of chapter 5, on pg 97.
    3. Finish one of the two programs I started, either (This assignment was difficulty for many folks; feel free to work on it through this week and give me what progress you have. Remember to include comments for what parts do or don't work. Getting pieces to work is better than nothing - the point is to better with practice, eh?)

  4. for Tues Sep 30
    1. Read chapters 6 (input) and 7 (subroutines). We won't be doing as much as Johnson does with regular expressions at this point.
    2. Do exercise 1 in section 6.6, pg 120. That is, write a program that reads in a file like
       mahoney:27
       fred:30
       mahoney:22
      
      and generates a report like
       User:  mahoney
       Total: 49
      
       User:  fred
       Total: 30
      
      A sample input file is at perl/input_for_sep30.txt.
    3. If you're inspired to look more at loops and conditionals, write a program that sorts a list of numbers. (There are many algorithms to do this. I'm not looking for a PhD thesis, just a nested loop that pulls out the smallest values one by one and builds up an ordered list.)

  5. for Tues Oct 7
    1. Read chapter 7.
    2. Go back over anything you've done this semester, and re-write it using subroutine calls. (Due Thurs)
    3. Do exercises 1 and 2 on page 140. (Due Thurs)
    4. TAKE HOME TEST out Fri, due Tues 8:30am.

  6. for Tues Oct 14
    1. Read chapter 8, on references. Skip 8.3 (function pointers and closures); it's more technical than we want right now.
    2. Do exercise 1 on page 159.
    3. Start one of the following programming projects, due on Thurs Oct 23 (Mon/Tues 20/21 are Hendricks Days). (That's two weeks away.) The final version will be graded. You should include documentation, tests, and sample input and output. I'll expect a progress report next Tues on the 14th. (Please don't leave this until the last minute; it's going to take some time.)

      • Tic Tac Toe
        Write a program that plays a stupid game of tic-tac-toe. The computer should play by picking a random square from the ones left open. The user should be asked where he wants to play. The board is printed after each move, and looks something like
          . | . | O
          - + - + -
          . | X | .
          - + - + -
          . | O | .
        
        where "." means an empty space, and "0" and "X" are marks for the two players. You'll want to construct this program piece by piece. You'll need to think about how to represent the board, and write routines for things like getting user input, generating a computer move, figuring out if someone has won, printing the board, and so on.

      • Geneology
        Write a program that allows the user to create, display, and edit a family tree. For each person, the program should remember at least name, parents, children (if any), spouse (if any). (You may assume 0 or 1 spouses, and that all children are from the same spouse, if you wish.) When run, the program should allow the user to add or modify entries, by typing in keywords from a menu of choices, as we have seen in earlier examples. It should also be able to print a text representation of the tree. Optionally, it might even answer questions (eg "show parents John Smith"). The suggested approach here is to use a data structure where each "person" is represented by a hash which includes pointers to other people. The specific design is up to you.

      • Your choice
        You may pick your own project, as long as it includes a data structure of some kind (Tic Tac Toe has its board; Geneology has its tree), subroutines which manipulate that data, and has some meat to it. Please run ideas by me before going hog wild.

  7. Tues Oct 21 - Hendrick's days

  8. for Tues Oct 27
    1. Start reading chapters 10 and 11 on regular expressions.
    2. Optional: try some of the exercises.

  9. for Tues Nov 4
    1. Finish reading chapters 10 and 11.
    2. Browse the regular expressions tutorial, quick start, and reference pages in the perl manual at perldoc.com
    3. Do at least two of the exercises from the end of chapters 10 and 11.

  10. for Tues Nov 11
    1. Read chapter 14, on modules, if you havn't already.
    2. Pick another project, and jump in. It'll be due before thanksgiving. If the tic-tac-toe felt unfinished but kind of interesting, you could pick another game and try that. We'll be starting to talk about web programming, so you could try something along those lines. Feel free to use any of the CPAN modules - with thos in hand, for example, you could write a web spider. Talk to me for other ideas. I want to have presentations in the week before Thanksgiving, so start early.
    3. Download, install, and try out at least one CPAN module of your choice. If nothing jumps out at you, try LWP::Simple. If you can't get it to work on your machine, talk to me for help, and/or get an account from me to run some interesting modules on cs.marlboro.edu

  11. for Tues Nov 18
    1. The textbook chapter on Objects (18) isn't great, but browse through that for a start.
    2. Please read through the online documentaion perlboot, perltoot, and perhaps perlobj, perltooc, and perlbot. You can find this at perldoc.com among other places.
    3. Write a short object oriented application that has objects ParkingLot, Vehicle, Car, and Truck. At a minimum these classes should each have (a) some internal data, and (b) some methods to edit and display that data. Both Car and Truck should inherit some methods from Vehicle. ParkingLot should be a place to put Vehicles, some of which are Cars and some of which are Trucks. Write methods that allow you to add a Vehicle to the lot, and that get each vehicle to describe itself. Vehicles should have (a) license plates, and (b) should identify themselves as cars or trucks. If you aren't getting anywhere with this, I'll define a more specific API; for now, see if you can set something up along these lines using an object oriented framework.
    4. Work on your projects.
  12. for Tues Nov 25
    1. Work on your projects, due by Wed Nov 26.
    2. Please be ready to show something in class. (If you send me some email ahead of time, I'll make your code visible online.)
  13. for Tues Dec 9
    1. Read about HTML and CGI from the following two tutorials:
    2. Create a CGI script on your cs.marlboro.edu account. How this works will be discussed in class.
  14. ** FINAL EXAM ** due Mon Dec 15
    1. online copy is here
    2. I'll hand it out on the last class, Tues Dec 9.
    3. Use any books, online static sources, or a perl compiler, but not other people. If you have questions, ask me.

Lecture Notes

Resources
  • Perlmonks.org - welcome to the monastary...
  • Perldoc.com - perl documentation
  • CPAN (Comprehensive Perl Archive Network) - modules for many purposes
  • An Intro to Perl and DNA string processing - a workshop I gave last year
  • Online library - full text of several perl books, including Beginning Perl, Picking Up Perl, and Embedding Perl in HTML with Mason
  • perl book reviews
  • Software
    • download Perl
    • CPAN - perl modules for any purpose
    • Editors
      • XEmacs - Jim's favorite; its installed on all the lab computers.
      • windows binary, local copy
      • At akbar's command prompt
      • Replacements for Notepad on Windows
        • TextPad (commercial, but you can download an free evaluation copy).
        • Edit+ (shareware)
      • Vim - another popular text editor for programmers
      • If all this is too much, you can start with just "Notepad" on Windows or "TextEdit" on a Macintosh.
  • Literate Programming - the author of our text is a big fan.
  • Books
    • Elements of Programming with Perl, Andrew Johnson (homepage for our textbook)
    • Programming Perl, Larry Wall - the Camel book
    • Perl Cookbook, Christiansen & Torkington
    • Object Oriented Perl, Damien Conway
    • Mastering Algorithms with Perl, Orwant et al
    • CGI Programming with Perl, Guelich et al
    • Beginning Perl for Bioinformatics, James Tisdall

Syllabus

Expect this to change as we go along.

 Sep  9, 11    chap 1-3   basic tools, background info, programming style
     16, 18         4,5   data types, control loops 
     23, 25         6,7   i/o, functions
     30,  2         8,9   references, documentation, examples  * test 1
 Oct  7,  9         14    using modules
     14, 16         10,11 regular expressions                  * 1st project
         22         15    debugging               
     23, 30         12    lists and hash techniques            * 2nd project
 Nov  4,  6         17    classic algorithms                   
     11, 13               web programming                      * final proposal
     18, 20         18,19 object
     24    
 Dec  2,  3         13    more i/o, more examples 
      9                                                        * final project

Jim Mahoney (mahoney@marlboro.edu)
Last modified <% scalar localtime($m->current_comp->create_time) %>