[Enter] [Course Objectives] [Schedule] [Text] [Grading] [Project]

Lab #2a: Perl intro

Objectives

  1. Write simple Perl programs

Background Material

0. Text: Chapter 9 [PDF] (Chapter 4 in Old Book)

1. Gentle Perl

2. Bill Grotsky's Perl slides [PDF]

3. Book and Other Examples

Assignment


Unlike the javascript assignment, this assignment is to be done entirely by you - searching the web for solutions is not allowed

1. (1 point) (INDIVIDUAL) Write a simple grep program in Perl. This program should have 2 arguments:

  1. A Regular Expression
  2. A file to be processed
Your program should search the file for all strings that match the regular expression, and then display each occurrence of a match on a separate line, printing out the entire line in which it occurs. For example, if I type:

grep '<title>' index.html, it would print out:

<head> <title> Lab 2 </title>
grep '<title>*.html
because this file index.html contains these 2 references to <title>

2. (1 point) (INDIVIDUAL) Extend the program in #1 to operate on all the files within the current directory. For example, if I were to type: grep '<title>'*.html
it would print out:

index.html: <head> <title> Lab 2 </title>
index.html: grep '<title>' *.html
indexsv.html: ...

because these files (not all shown) contain references to <title>.

3. (1 point) Extend the program in #2 to include a 3rd parameter, n, representing the size of the text window to be displayed. It should still display each occurrence of a match on a separate line, surrounded by its context on either side; the matched string plus the left and right contexts (count spaces too) should be n characters in total.

4. (1 point) Begin your audience analysis : Create the questions, decide who you will send it to (Except for the Ruby lab, do not send to this class!), etc. Put a link to this rough draft on your Project Description page. In the next lab, you will create the form which your potential users can fill out and return to you. For this and all project work, all partners must put a link on their page.

5. (1 point) Create a) the top-level page for your project and b) a style sheet you will apply to its presentation, and c) A bibliography of sites related to the one you are creating. Include a one or two line sentence underneath (indent it too) each reference describing the page. For example,
http://www.csulb.edu/~txie/online.htm

for a site to teach Chinese. Again, put links to these on your project page. You may want to call it Related Links. If this is inappropriate for your project (check with me), put this bibliography on the Project Description page. The top level page will evolve into your actual project. Make it look nice! Your project pages should be conforming (Remember to eMail me if you want to put something non-conforming in later)

Don't forget to do the quiz

Quiz [PDF]

Quiz Solutions [PDF]