Branching; Looping, Arrays, File manipulation; Regular expressions; Perl and CGI Scripts
HW # 9 (due end of Week 13) Write a Perl script which converts any input string by replacing all voiceless consonants into voiced ones and vice versa. E-mail the script to me. HW # 10 (due end of Week 14) Write a Perl script which extracts suffixes entered by the user from any given textual corpus. E-mail the script to me. Final Project (due end of Week 16): Export your dictionary from HW # 8 into a text file. Write a HTML form and a Perl code to be used as a CGI script which will query your database according to the headword, the equivalent, POS tag and the usage label. E-mail the dictionary text file, the html form, and the Perl cgi script to me.
You first have to get the Perl interpreter program and install it on your machine:
If you are using a Unix-based platform, such as Linux, the intepreter will be on your platform and if you would like to switch to the Linux platform, you can download it free of charge at the:
Linux Main Page
If you want to run Perl on your Windows platform, you can get it at the:
ActiveState Pages
Mac users should download the Perl interpreter from the:
MacPerl Pages
| Element | Example | Comment |
| Simple ariable | $b, $word | Any string preceeded by a $. Stores both numerical and alphanumerical values |
| Default Input and Pattern Searching Variable | $_ | |
| Keyboard Input/Output | STDIN | Reserved word |
| File Input/Output | IN, OUT, FILE1 | Any uppercase word |
| Array | @b, @array | Any string preceded by a @, stores sequences of numerical and alphanumerical data |
| Operators | Example | Comment |
| Diamond operator | <> | reads one line at a time into $_ |
| Math operators | +, -, /, *; | addition, subtraction, division, multiplication, e.g. $a=$a+1 or $a++ |
| Logical operators | ||, &, ! | or, and, not |
| Comparison operators, numeric | ==, !=, >, <, =>, <= | equal, not equal, greater than, less than, equal or greater than, equal or less than - used to compare numbers |
| Comparison operators, alphanumeric | eq, ne, gt, lt, ge, le | equal, not equal, greater than, less than, equal or greater than, equal or less than - used to compare strings |
| Instructions | Example | Comment |
| Start and End | { } | { opens a block of instructions, } closes it |
| Branching | if () {} | Performs an instruction {} if the condition () is met, e.g. if ($a="yes") {$b++;} |
| Multiple branching | if () {} elsif () {} else {} | Performs an instruction {} if the condition () is met, if elsif () condition is met, other instruction is performed, in all other instances the else {} instruction is executed, e.g., if ($weight < 120) {print "You are slim";} elsif ($weight > 180) {print "Hmmm!"} else {print "Just right.";} |
| For loops | for (a; b; c) {} | Loops from a to b at the rate c, e.g., for ($a=1; $a=5; $a++) {print "$a ";} |
Read this indepth review of regular expressions
| Script | Source |
| Sequence Search Script | Sequence search Source |
| Frequency Count Script | Frequency Count Source |
To facilitate your final course project, I have made available the the Perl script behind the S-Cr Polish Dictionary and the dictionary database
This is how you pass the variables from a html form to the Perl script. The following script takes the name entered and then prints Hi + that name.
hi.html file
<html>
<head>
<title>Hi</title>
</head>
<body>
<form action="http://cli.la.asu.edu/cgi-bin/hi.pl" method=post>
Your name: <INPUT name=name size=60> <INPUT type=submit value='Send'>
</form>
</body>
</html>
hi.pl file
#!/usr/bin/perl
use CGI qw/:standard/;
$q = new CGI;
$name = $q->param('name');
print "Content-type: text/html; charset=windows-1250\n\n";
print start_html;
print "Hello $name";
print end_html;
The following technologies are most commonly used to preform the tasks in the fields covered in this course. Once you master Perl, it will be relatively easy to learn any and each of them. The following tutorials are good starting points.
Books
There are two general books of computational lingusitics most commonly used in the US.
The book by Jurafski and Martin should be used by linguists and programmers. It is excellent straightforward introduction into this field.
Use the book by Manning and Schutze could be used only if you have strong mathematical/statistical background and interest.
Mike Hammond has published two excellent practical books on programming for linguists. I highly recommend both of them, one for
Perl and the other for
Java
What do you know (paste this in your resume):