CSE 303: Concepts and Tools for Software Development, Winter 2008
  CSE Home   About Us   Search   Contact Info 
 
Course Home
 Home
Administation
 Overview
 Course Wiki
 Email archive
 Anonymous feedback
 View feedback
 Homework Turnin
 
Most Everything
 Schedule
 
Other Information
 UW/ACM Tutorials
 303 Computing: Getting Started
   

Perl Sample Code

  • example.pl
    This isn't a program so much as snippets of Perl code. The comments try to tell you what the snippets do. Looking at the code and what it outputs together will also help tell you what it does.

    You can try out these snippets (or any Perl snippets) like this:

    • perl -d -e 0 gets you into interactive perl
    • Now type lines of code. (Do not use "my" to declare variables. They'll be created in a context that disappears as soon as the line is executed, and so are counterproductive when using the interactive debugger).
    • A new line ends a statement - not just a semicolon.

    Example invocation: ./example.pl
    Another way: perl example.pl

    (The first way works only if the file has execute permission.)

  • plwc.pl
    An implementation of the word count assignment, in perl.

    Example invocation: ./plwc.pl myInputFile

  • plgrep.pl
    Implements a very primitive version of the Unix program grep.

    General invocation:./plgrep.pl 'perl_regular_expression' inputfile
    Be careful with the regular expression. Quote it with apostrophes.

    Example invocation:./plgrep.pl '\s\w*a\w*e\w*i\w*o\w*u\w*\s' inputfile
    Looks for a word (preceded and followed by white space) in which the vowels appear in order.
    Note: This program gives you what is in some cases a handy way to test/debug perl regular expressions you want to use in some program.

  • plawk.pl
    A program in the spirit of the awk program. All it does is read its input and break it up into tokens (which is a key feature of awk).

    Example invocation:./plawk.pl inputFile

  • userShell.pl
    Processes the /etc/passwd file to print the login shell and username of each user.

    Example invocation: ./userShell.pl


Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX
[comments to zahorjan at cs.washington.edu]