Programming in Python, Perl and PHP: CSCI 394.51

Adam Parrish, Adjunct Lecturer
aparrish@hunter.cuny.edu

Lecture notes | Syllabus | Assignment 1 | Assignment 2 | Assignment 3

Assignment #1

Due date: Jan 10th, 2011, 11:59pm.

Take one of the examples discussed in class and modify it. Your modified program must incorporate at least one (and preferably more than one!) feature of PHP that was not presented in class. (Some examples of PHP features that you could use: operators, built-in variables, syntactic functions from the PHP library; syntactic structures like switch, variable functions, etc.)

As part of your assignment, you must send me a copy of your source code (or e-mail me with the location of the source code on, e.g., the sandbox server). Your e-mail should include a brief description of what your program/project/piece does, along with an example of what kind of input it expects (if any) and what kind of output it produces.

You will be evaluated (out of 15 points) based on your mastery of the concepts discussed in class, your ingenuity in applying concepts from outside of class, and the creativity of your concept.

Here are some ideas to get you started.

  • Find some data online in text format. Use PHP to parse data out of the file and produce some kind of output. (See in-class example stats.php)
  • Create a program that takes arbitrary text data as input, and produces statistical data about the text. For example: count words of a particular length; words beginning with a particular letter; most frequent characters; etc. (See in-class example concordance.php)
  • Create a program that creatively transforms text by (a) omitting certain lines and/or (b) replacing certain strings with other strings. This program could be designed to work on a particular source text (see in-class example replace_rand.php), or to work on arbitrary text.
  • Take any of the programs demonstrated in-class, or any program that conforms to (1)-(3) above, and—using Markov.php/markov_web.php as a model—make it accessible via the web. (You should write a class that encapsulates your text transformation/analysis algorithm, and then write a PHP program that allows users to send input to an object of that class, then return it via HTML.)

Assignment #2

Due date: January 18th 2011, 11:59pm.

Choose one of the four following options. (For options 3 and 4, feel free to omit use strict and use warnings.)

  1. Follow the instructions for Assignment #1, but use Perl instead of PHP. Take one of the examples presented in class and modify it in some way, incorporating some feature of Perl we didn't discuss in class in the process.
  2. Translate your project from assignment #1 into Perl. (If your project was web-based, look into Perl's CGI module.)
  3. (Advanced!) Take one of the Perl scripts presented in class and duplicate its functionality as (a) a one-liner script that can be run directly on the command-line; (b) an obfuscated Perl script; or (c) a Perl script that economizes space over other priorities (e.g., set yourself a character limit and try to get your program under that limit).
  4. (Advanced!) Write a Perl poem. Your program need not produce any useful output; it only needs to compile and run with no errors.

As part of your assignment, you must send me a copy of your source code (or e-mail me with the location of the source code on, e.g., the sandbox server). Your e-mail should include a brief description of what your program/project/piece does, along with an example of what kind of input it expects (if any) and what kind of output it produces.

You will be evaluated (out of 15 points) based on your mastery of the concepts discussed in class, your ingenuity in applying concepts from outside of class, and the creativity of your concept.

Assignment #3

Due date: January 24th 2011, in my inbox before the start of the exam.

Choose one of the two following options.

  1. Follow the instructions for Assignment #1, but use Pythoninstead of PHP. Take one of the examples presented in class and modify it in some way, incorporating some feature of Python we didn't discuss in class in the process.
  2. Translate your project from Assignment #1 or Assignment #2 into Python.

As part of your assignment, you must send me a copy of your source code (or e-mail me with the location of the source code on, e.g., the sandbox server). Your e-mail should include a brief description of what your program/project/piece does, along with an example of what kind of input it expects (if any) and what kind of output it produces.

You will be evaluated (out of 15 points) based on your mastery of the concepts discussed in class, your ingenuity in applying concepts from outside of class, and the creativity of your concept.

sandbox.decontextualize.com policies

Unless you've obtained prior permission, please do not use this server for hosting (uploading or downloading!) large files. I have to pay for bandwidth! Also, please refrain from linking to files or scripts hosted on this site. One boingboing link and I'm in the poor house. Thanks!

Note: After the final day of class, the server will be taken offline (forever!). Please make sure to have your files off of the server by then. Always keep local copies of your work!