Perl Programming - Bslides
Transcript of Perl Programming - Bslides
-
8/8/2019 Perl Programming - Bslides
1/145
Perl for Linguists
Michael Hammond
University of Arizona
Perl for Linguists p.1/3
-
8/8/2019 Perl Programming - Bslides
2/145
Perl for linguists
Perl for Linguists p.2/3
-
8/8/2019 Perl Programming - Bslides
3/145
Perl for linguists Why programming?
Perl for Linguists p.2/3
-
8/8/2019 Perl Programming - Bslides
4/145
Perl for linguists Why programming? Why Perl?
Perl for Linguists p.2/3
-
8/8/2019 Perl Programming - Bslides
5/145
Perl for linguists Why programming? Why Perl?
Learn a little Perl.
Perl for Linguists p.2/3
-
8/8/2019 Perl Programming - Bslides
6/145
Perl for linguists Why programming? Why Perl?
Learn a little Perl. More advanced Perl. . .
Perl for Linguists p.2/3
-
8/8/2019 Perl Programming - Bslides
7/145
Why programming?
Perl for Linguists p.3/3
-
8/8/2019 Perl Programming - Bslides
8/145
Why programming? Collect data
Perl for Linguists p.3/3
-
8/8/2019 Perl Programming - Bslides
9/145
Why programming? Collect data
Analyze data
Perl for Linguists p.3/3
-
8/8/2019 Perl Programming - Bslides
10/145
Why programming? Collect data
Analyze data Model theory
Perl for Linguists p.3/3
-
8/8/2019 Perl Programming - Bslides
11/145
Why programming? Collect data
Analyze data Model theory
General professional skills
Perl for Linguists p.3/3
-
8/8/2019 Perl Programming - Bslides
12/145
Code for this tutorialAll the code for this presentation is available over
the web at the following URL:
http://linguistics.arizona.edu/~hammond/berkeley.html
Perl for Linguists p.4/3
http://linguistics.arizona.edu/~hammond/berkeley.htmlhttp://linguistics.arizona.edu/~hammond/berkeley.html -
8/8/2019 Perl Programming - Bslides
13/145
Unzipping the programs1. Download the file programfiles.zip by
right-clicking on the link, selecting save targetas, and selecting your desktop as thedestination.
2. Unzip the file by double-clicking on thedownloaded file on your desktop and movingall the files there to a new directory on the
desktop.
3. Open the MS-DOS prompt in the newdirectory by double-clicking on the filedoswindow.bat.
Perl for Linguists p.5/3
-
8/8/2019 Perl Programming - Bslides
14/145
Collecting data
Perl for Linguists p.6/3
-
8/8/2019 Perl Programming - Bslides
15/145
Collecting data Running experiments locally (expprog.pl)
Perl for Linguists p.6/3
-
8/8/2019 Perl Programming - Bslides
16/145
Collecting data Running experiments locally (expprog.pl)
Running experiments locally with a GUI(tkexp.pl)
Perl for Linguists p.6/3
-
8/8/2019 Perl Programming - Bslides
17/145
Collecting data Running experiments locally (expprog.pl)
Running experiments locally with a GUI(tkexp.pl)
Running experiments remotely(Bailey & Hahn replication, bhrep.cgi)
Perl for Linguists p.6/3
http://linguistics.arizona.edu/cgi-bin/bhrep.cgihttp://linguistics.arizona.edu/cgi-bin/bhrep.cgi -
8/8/2019 Perl Programming - Bslides
18/145
Collecting data Running experiments locally (expprog.pl)
Running experiments locally with a GUI(tkexp.pl)
Running experiments remotely(Bailey & Hahn replication, bhrep.cgi)
Assembling corpora from local static
resources (makecorpus.pl)
Perl for Linguists p.6/3
http://linguistics.arizona.edu/cgi-bin/bhrep.cgihttp://linguistics.arizona.edu/cgi-bin/bhrep.cgi -
8/8/2019 Perl Programming - Bslides
19/145
Collecting data Running experiments locally (expprog.pl)
Running experiments locally with a GUI(tkexp.pl)
Running experiments remotely(Bailey & Hahn replication, bhrep.cgi)
Assembling corpora from local static
resources (makecorpus.pl) Assembling corpora from nonlocal dynamic
resources: the web (websearch.pl)
Perl for Linguists p.6/3
http://linguistics.arizona.edu/cgi-bin/bhrep.cgihttp://linguistics.arizona.edu/cgi-bin/bhrep.cgi -
8/8/2019 Perl Programming - Bslides
20/145
Analyzing data
Perl for Linguists p.7/3
-
8/8/2019 Perl Programming - Bslides
21/145
Analyzing data Looking for patterns (visgrep.pl)
Perl for Linguists p.7/3
-
8/8/2019 Perl Programming - Bslides
22/145
Analyzing data Looking for patterns (visgrep.pl)
Counting things (neightk.pl)
Perl for Linguists p.7/3
-
8/8/2019 Perl Programming - Bslides
23/145
Analyzing data Looking for patterns (visgrep.pl)
Counting things (neightk.pl) Finding verbs (verbs.pl)
Perl for Linguists p.7/3
-
8/8/2019 Perl Programming - Bslides
24/145
Modeling theory
Perl for Linguists p.8/3
-
8/8/2019 Perl Programming - Bslides
25/145
Modeling theory
Optimality Theory (web interface,
sylpars.pl)
Perl for Linguists p.8/3
http://wacky.ccit.arizona.edu/~ling/mhspf.htmlhttp://wacky.ccit.arizona.edu/~ling/mhspf.html -
8/8/2019 Perl Programming - Bslides
26/145
Modeling theory
Optimality Theory (web interface,
sylpars.pl) N-gram models (a bunch of examples from a
course on Statistical NLP that I did recently)
Perl for Linguists p.8/3
http://wacky.ccit.arizona.edu/~ling/mhspf.htmlhttp://linguistics.arizona.edu/~hammond/ling696f-sp03/http://linguistics.arizona.edu/~hammond/ling696f-sp03/http://wacky.ccit.arizona.edu/~ling/mhspf.html -
8/8/2019 Perl Programming - Bslides
27/145
General professional skills
Perl for Linguists p.9/3
-
8/8/2019 Perl Programming - Bslides
28/145
General professional skills
General programming skills
Perl for Linguists p.9/3
-
8/8/2019 Perl Programming - Bslides
29/145
General professional skills
General programming skills
Web programming
Perl for Linguists p.9/3
-
8/8/2019 Perl Programming - Bslides
30/145
Why Perl?
Perl for Linguists p.10/3
-
8/8/2019 Perl Programming - Bslides
31/145
Why Perl?
Free
Perl for Linguists p.10/3
-
8/8/2019 Perl Programming - Bslides
32/145
Why Perl?
! Free!
Multi-platform
Perl for Linguists p.10/3
-
8/8/2019 Perl Programming - Bslides
33/145
Why Perl?
" Free"
Multi-platform" Easy
Perl for Linguists p.10/3
-
8/8/2019 Perl Programming - Bslides
34/145
Why Perl?
# Free#
Multi-platform# Easy#
Multiple dialects
Perl for Linguists p.10/3
-
8/8/2019 Perl Programming - Bslides
35/145
Why Perl?
$ Free$
Multi-platform$ Easy$
Multiple dialects$ Powerful regular expression tools
Perl for Linguists p.10/3
-
8/8/2019 Perl Programming - Bslides
36/145
Why Perl?
% Free%
Multi-platform% Easy%
Multiple dialects% Powerful regular expression tools% Written by a linguist
Perl for Linguists p.10/3
http://www.acm.org/crossroads/xrds1-2/lwall.htmlhttp://www.acm.org/crossroads/xrds1-2/lwall.html -
8/8/2019 Perl Programming - Bslides
37/145
Why Perl?
& Free&
Multi-platform& Easy&
Multiple dialects& Powerful regular expression tools& Written by a linguist& Perl poetry
Perl for Linguists p.10/3
http://www.acm.org/crossroads/xrds1-2/lwall.htmlhttp://www.programming-x.com/programming/perl-poetry.htmlhttp://www.programming-x.com/programming/perl-poetry.htmlhttp://www.acm.org/crossroads/xrds1-2/lwall.html -
8/8/2019 Perl Programming - Bslides
38/145
Why Perl?
' Free'
Multi-platform' Easy'
Multiple dialects' Powerful regular expression tools' Written by a linguist' Perl poetry' Obfuscated perl, japhs, etc.
Perl for Linguists p.10/3
http://www.acm.org/crossroads/xrds1-2/lwall.htmlhttp://www.programming-x.com/programming/perl-poetry.htmlhttp://www.cpan.org/misc/japhhttp://www.cpan.org/misc/japhhttp://www.programming-x.com/programming/perl-poetry.htmlhttp://www.acm.org/crossroads/xrds1-2/lwall.html -
8/8/2019 Perl Programming - Bslides
39/145
Learn a little perl. . .
Perl for Linguists p.11/3
-
8/8/2019 Perl Programming - Bslides
40/145
Learn a little perl. . .
( Windows basics
Perl for Linguists p.11/3
-
8/8/2019 Perl Programming - Bslides
41/145
Learn a little perl. . .
) Windows basics)
Perl syntax
Perl for Linguists p.11/3
-
8/8/2019 Perl Programming - Bslides
42/145
Learn a little perl. . .
0 Windows basics0
Perl syntax0 IO
Perl for Linguists p.11/3
-
8/8/2019 Perl Programming - Bslides
43/145
Learn a little perl. . .
1 Windows basics1
Perl syntax1 IO1
Regular expressions
Perl for Linguists p.11/3
-
8/8/2019 Perl Programming - Bslides
44/145
Learn a little perl. . .
2 Windows basics2
Perl syntax2 IO2
Regular expressions2 Where to find out more
Perl for Linguists p.11/3
-
8/8/2019 Perl Programming - Bslides
45/145
Windows basics
Perl for Linguists p.12/3
-
8/8/2019 Perl Programming - Bslides
46/145
Windows basics3 It is easiest to invoke perl programs from the
DOS prompt. (If configured properly, you canjust double-click them though.)
Perl for Linguists p.12/3
-
8/8/2019 Perl Programming - Bslides
47/145
Windows basics4 It is easiest to invoke perl programs from the
DOS prompt. (If configured properly, you canjust double-click them though.)4
perl myprogram.pl: invokes the perl
interpreter with a program myprogram.pl.
Perl for Linguists p.12/3
-
8/8/2019 Perl Programming - Bslides
48/145
Windows basics5 It is easiest to invoke perl programs from the
DOS prompt. (If configured properly, you canjust double-click them though.)5
perl myprogram.pl: invokes the perl
interpreter with a program myprogram.pl.5
ctrl-c: stops the current program
Perl for Linguists p.12/3
-
8/8/2019 Perl Programming - Bslides
49/145
A goal
6 We will build our efforts around an example
program: a program that parses a text file inEnglish into sentences and then tries to findall the verbs (verbs.pl).
6
This exemplifies simple data and controlstructures and what we might callcomputational linguistic reasoning.
6
We wont get to the full version of thisprogramits infinitely expandableactuallybut we can get a good start.
Perl for Linguists p.13/3
P i i
-
8/8/2019 Perl Programming - Bslides
50/145
Programming overview
Perl for Linguists p.14/3
P i i
-
8/8/2019 Perl Programming - Bslides
51/145
Programming overview
7 Implement some idea as perl code (write theprogram).
Perl for Linguists p.14/3
P i i
-
8/8/2019 Perl Programming - Bslides
52/145
Programming overview
8 Implement some idea as perl code (write theprogram).
8 Convert code into something the computercan execute (run perl on your code).
Perl for Linguists p.14/3
P i i
-
8/8/2019 Perl Programming - Bslides
53/145
Programming overview
9 Implement some idea as perl code (write theprogram).
9 Convert code into something the computercan execute (run perl on your code).
9
Program execution (run perl on your code).
Perl for Linguists p.14/3
P i i
-
8/8/2019 Perl Programming - Bslides
54/145
Programming overview
@ Implement some idea as perl code (write theprogram).
@ Convert code into something the computercan execute (run perl on your code).
@
Program execution (run perl on your code).@ Results (what happens as a consequence).
Perl for Linguists p.14/3
P l t
-
8/8/2019 Perl Programming - Bslides
55/145
Perl syntax
Perl for Linguists p.15/3
Perl syntax
-
8/8/2019 Perl Programming - Bslides
56/145
Perl syntax
A A perl program is a series of statements.
Perl for Linguists p.15/3
Perl syntax
-
8/8/2019 Perl Programming - Bslides
57/145
Perl syntax
B A perl program is a series of statements.B
Statements can be organized into groups.
Perl for Linguists p.15/3
Perl syntax
-
8/8/2019 Perl Programming - Bslides
58/145
Perl syntax
C A perl program is a series of statements.C
Statements can be organized into groups.C Statements are operations on some bit of
data, e.g. print this string, add these
numbers, etc.
Perl for Linguists p.15/3
Perl syntax
-
8/8/2019 Perl Programming - Bslides
59/145
Perl syntax
D A perl program is a series of statements.D
Statements can be organized into groups.D Statements are operations on some bit of
data, e.g. print this string, add these
numbers, etc.D Groups of statements can apply:
1. only when specific conditions hold, or2. more than once, etc.
Perl for Linguists p.15/3
St t t
-
8/8/2019 Perl Programming - Bslides
60/145
Statements
Perl for Linguists p.16/3
St t t
-
8/8/2019 Perl Programming - Bslides
61/145
Statements
E A statement includes some operation(typically marked with following parentheses),ends with a semicolon, and may containmore. For example:
Perl for Linguists p.16/3
Statements
-
8/8/2019 Perl Programming - Bslides
62/145
Statements
F A statement includes some operation(typically marked with following parentheses),ends with a semicolon, and may containmore. For example:
F
print("Hello!"); (prints the stringHello!)
Perl for Linguists p.16/3
Statements
-
8/8/2019 Perl Programming - Bslides
63/145
Statements
G A statement includes some operation(typically marked with following parentheses),ends with a semicolon, and may containmore. For example:
G
print("Hello!"); (prints the stringHello!)G
rand(5); (gets a random number between 0
and 5)
Perl for Linguists p.16/3
Statements
-
8/8/2019 Perl Programming - Bslides
64/145
Statements
H A statement includes some operation(typically marked with following parentheses),ends with a semicolon, and may containmore. For example:
H
print("Hello!"); (prints the stringHello!)H
rand(5); (gets a random number between 0
and 5)H
localtime(); (gets the current time)
Perl for Linguists p.16/3
Try it
-
8/8/2019 Perl Programming - Bslides
65/145
Try it
Perl for Linguists p.17/3
Try it
-
8/8/2019 Perl Programming - Bslides
66/145
Try it
1. Open the DOS window (through the startmenu or by clicking on the doswindow.baticon.)
Perl for Linguists p.17/3
Try it
-
8/8/2019 Perl Programming - Bslides
67/145
Try it
1. Open the DOS window (through the startmenu or by clicking on the doswindow.baticon.)
2. Type edit myprogram.pl
Perl for Linguists p.17/3
Try it
-
8/8/2019 Perl Programming - Bslides
68/145
Try it
1. Open the DOS window (through the startmenu or by clicking on the doswindow.baticon.)
2. Type edit myprogram.pl
3. Type print("I am a linguist!");
Perl for Linguists p.17/3
Try it
-
8/8/2019 Perl Programming - Bslides
69/145
y t
1. Open the DOS window (through the startmenu or by clicking on the doswindow.baticon.)
2. Type edit myprogram.pl
3. Type print("I am a linguist!");
4. Select Save and then Exit from the Filemenu.
Perl for Linguists p.17/3
Try it
-
8/8/2019 Perl Programming - Bslides
70/145
y
1. Open the DOS window (through the startmenu or by clicking on the doswindow.baticon.)
2. Type edit myprogram.pl
3. Type print("I am a linguist!");
4. Select Save and then Exit from the Filemenu.
5. Type perl myprogram.pl at the prompt.
Perl for Linguists p.17/3
Variables
-
8/8/2019 Perl Programming - Bslides
71/145
Variables
Perl for Linguists p.18/3
Variables
-
8/8/2019 Perl Programming - Bslides
72/145
Variables
I Notice how rand() and localtime() dontseem to do anything.
Perl for Linguists p.18/3
Variables
-
8/8/2019 Perl Programming - Bslides
73/145
Variables
P Notice how rand() and localtime() dontseem to do anything.
P What they do is return a string. You can savethat result and then print it:
Perl for Linguists p.18/3
Variables
-
8/8/2019 Perl Programming - Bslides
74/145
Variables
Q Notice how rand() and localtime() dontseem to do anything.
Q What they do is return a string. You can savethat result and then print it:
$myvariable = localtime();
print($myvariable);
Perl for Linguists p.18/3
Variables
-
8/8/2019 Perl Programming - Bslides
75/145
Va ab es
Perl for Linguists p.19/3
Variables
-
8/8/2019 Perl Programming - Bslides
76/145
R Simple scalar variables: $myvar,$aVariable, $x.
Perl for Linguists p.19/3
Variables
-
8/8/2019 Perl Programming - Bslides
77/145
S Simple scalar variables: $myvar,$aVariable, $x.
S A value is assigned to a variable with theassignment operator =.
Perl for Linguists p.19/3
Variables
-
8/8/2019 Perl Programming - Bslides
78/145
T Simple scalar variables: $myvar,$aVariable, $x.
T A value is assigned to a variable with theassignment operator =.
T
Variables can hold numbers, strings, etc.
Perl for Linguists p.19/3
Reading a file
-
8/8/2019 Perl Programming - Bslides
79/145
Perl for Linguists p.20/3
Reading a file
-
8/8/2019 Perl Programming - Bslides
80/145
U First use open() to open a file and associateit with a handle, e.g.open(F, "myfile.txt");.
Perl for Linguists p.20/3
Reading a file
-
8/8/2019 Perl Programming - Bslides
81/145
V First use open() to open a file and associateit with a handle, e.g.open(F, "myfile.txt");.
V Read a line from the file with record-reading
operator:
W
F
X
.
Perl for Linguists p.20/3
Reading a file
-
8/8/2019 Perl Programming - Bslides
82/145
Y First use open() to open a file and associateit with a handle, e.g.open(F, "myfile.txt");.
Y Read a line from the file with record-reading
operator:
F
a
.Y When youre done, close the handle:
close(F);.
Perl for Linguists p.20/3
Sample code
-
8/8/2019 Perl Programming - Bslides
83/145
open(F,"myfile.txt");
$line = ;
print($line);close(F);
Perl for Linguists p.21/3
Control structures
-
8/8/2019 Perl Programming - Bslides
84/145
b
if: conditional applicationb
while: iteration as long as some condition istrueb
for: iteration for a specific number of timesb
foreach: iteration for every member of a list
Perl for Linguists p.22/3
More sample code
-
8/8/2019 Perl Programming - Bslides
85/145
open(F,"myfile.txt");
while ($line = ) {
print($line);}
close(F);
Perl for Linguists p.23/3
Arrays
-
8/8/2019 Perl Programming - Bslides
86/145
Perl for Linguists p.24/3
Arrays
-
8/8/2019 Perl Programming - Bslides
87/145
c Array variables: a list of variables groupedtogether: @myarray, @thisBigArray,@them.
Perl for Linguists p.24/3
Arrays
-
8/8/2019 Perl Programming - Bslides
88/145
d Array variables: a list of variables groupedtogether: @myarray, @thisBigArray,
@them.d Adding an element to the end of an array:
push(@myarray, "hat");.
Perl for Linguists p.24/3
Arrays
-
8/8/2019 Perl Programming - Bslides
89/145
e Array variables: a list of variables groupedtogether: @myarray, @thisBigArray,
@them.e Adding an element to the end of an array:
push(@myarray, "hat");.e Retrieving an element from the end of an
array: $it = pop(@myarray);.
Perl for Linguists p.24/3
Arrays
-
8/8/2019 Perl Programming - Bslides
90/145
f Array variables: a list of variables groupedtogether: @myarray, @thisBigArray,
@them.f Adding an element to the end of an array:
push(@myarray, "hat");.f Retrieving an element from the end of an
array: $it = pop(@myarray);.f
Retrieving a specific element:print($myarray[4]); (array indices startat 0).
Perl for Linguists p.24/3
Sample code again
-
8/8/2019 Perl Programming - Bslides
91/145
open(F,"myfile.txt");
while ($line = ) {
push(@mylines, $line);}
close(F);
foreach $theline (@mylines) {print($theline);
}
Perl for Linguists p.25/3
Regular expressions
-
8/8/2019 Perl Programming - Bslides
92/145
Perl for Linguists p.26/3
Regular expressions
-
8/8/2019 Perl Programming - Bslides
93/145
g Regular expression: a restrictive way ofindicating string patterns.
Perl for Linguists p.26/3
Regular expressions
-
8/8/2019 Perl Programming - Bslides
94/145
h Regular expression: a restrictive way ofindicating string patterns.
h
$myvar =~ /regexp/: does $myvarcontain the regular expression?
Perl for Linguists p.26/3
Regular expressions
-
8/8/2019 Perl Programming - Bslides
95/145
i Regular expression: a restrictive way ofindicating string patterns.
i
$myvar =~ /regexp/: does $myvarcontain the regular expression?
i
$myvar =~ s/regexp/string/: if$myvar contains the regular expression,replace it with the string.
Perl for Linguists p.26/3
The verb-finding program
-
8/8/2019 Perl Programming - Bslides
96/145
Perl for Linguists p.27/3
The verb-finding program
-
8/8/2019 Perl Programming - Bslides
97/145
p Recall that the program breaks an Englishtext file into sentences and does its best at
finding all the verbs.
Perl for Linguists p.27/3
The verb-finding program
-
8/8/2019 Perl Programming - Bslides
98/145
q Recall that the program breaks an Englishtext file into sentences and does its best at
finding all the verbs.q An hour is not enough time to figure out how
to do all of this, but just the bits weve coveredare a lot of it (verbs.pl).
Perl for Linguists p.27/3
Where to find out more
-
8/8/2019 Perl Programming - Bslides
99/145
Perl for Linguists p.28/3
Where to find out more
-
8/8/2019 Perl Programming - Bslides
100/145
r The free ActiveState Perl were using comeswith extensive web-based documentation.
Perl for Linguists p.28/3
Where to find out more
-
8/8/2019 Perl Programming - Bslides
101/145
s The free ActiveState Perl were using comeswith extensive web-based documentation.
s In any perl implementation the perldoccommand can be used to find out lots andlots of stuff.
Perl for Linguists p.28/3
Where to find out more
-
8/8/2019 Perl Programming - Bslides
102/145
t The free ActiveState Perl were using comeswith extensive web-based documentation.
t In any perl implementation the perldoccommand can be used to find out lots andlots of stuff.
t The official and best perl website iswww.cpan.org, but see also www.perl.org.
Perl for Linguists p.28/3
Advanced stuff
http://www.cpan.org/http://www.perl.org/http://www.perl.org/http://www.cpan.org/ -
8/8/2019 Perl Programming - Bslides
103/145
Perl for Linguists p.29/3
Advanced stuff
-
8/8/2019 Perl Programming - Bslides
104/145
u Lets now do some more advanced stuff.
Perl for Linguists p.29/3
Advanced stuff
-
8/8/2019 Perl Programming - Bslides
105/145
v Lets now do some more advanced stuff.v Advanced in terms of perl.
Perl for Linguists p.29/3
Advanced stuff
-
8/8/2019 Perl Programming - Bslides
106/145
w Lets now do some more advanced stuff.w Advanced in terms of perl.w Advanced in terms of linguistics.
Perl for Linguists p.29/3
Advanced perl
-
8/8/2019 Perl Programming - Bslides
107/145
Perl for Linguists p.30/3
Advanced perl
Obj i d i d bli l
-
8/8/2019 Perl Programming - Bslides
108/145
x Object-oriented programming and public perlmodules
Perl for Linguists p.30/3
Advanced perl
Obj t i t d i d bli l
-
8/8/2019 Perl Programming - Bslides
109/145
y Object-oriented programming and public perlmodules
y
Tk (editperl.pl, visgrep.pl)
Perl for Linguists p.30/3
Advanced perl
Obj t i t d i d bli l
-
8/8/2019 Perl Programming - Bslides
110/145
Object-oriented programming and public perlmodules
Tk (editperl.pl, visgrep.pl) Remote computing (bhexp.cgi, dbiex.pl,
websearch.pl)
Perl for Linguists p.30/3
Object-oriented programming
-
8/8/2019 Perl Programming - Bslides
111/145
Perl for Linguists p.31/3
Object-oriented programming
Object oriented (OO) programming is another
-
8/8/2019 Perl Programming - Bslides
112/145
Object-oriented (OO) programming is anotherstyle of programming.
Perl for Linguists p.31/3
Object-oriented programming
Object oriented (OO) programming is another
-
8/8/2019 Perl Programming - Bslides
113/145
Object-oriented (OO) programming is anotherstyle of programming.
OO Programs are a network of things orobjects, not a list of commands.
Perl for Linguists p.31/3
Object-oriented programming
Object oriented (OO) programming is another
-
8/8/2019 Perl Programming - Bslides
114/145
Object-oriented (OO) programming is anotherstyle of programming.
OO Programs are a network of things orobjects, not a list of commands.
Objects have their own data and specializedfunctions for dealing with their own data.
Perl for Linguists p.31/3
Object-oriented programming
Object oriented (OO) programming is another
-
8/8/2019 Perl Programming - Bslides
115/145
Object-oriented (OO) programming is anotherstyle of programming.
OO Programs are a network of things orobjects, not a list of commands.
Objects have their own data and specializedfunctions for dealing with their own data. Objects can be refer to other objects or inherit
the properties of other objects.
Perl for Linguists p.31/3
Translating to OO
-
8/8/2019 Perl Programming - Bslides
116/145
Perl for Linguists p.32/3
Translating to OO
Original verb-finding program: verbs pl
-
8/8/2019 Perl Programming - Bslides
117/145
Original verb finding program: verbs.pl.
Perl for Linguists p.32/3
Translating to OO
Original verb-finding program: verbs pl
-
8/8/2019 Perl Programming - Bslides
118/145
Original verb finding program: verbs.pl. OO verb-finding program: verbsOO.pl.
Perl for Linguists p.32/3
Caveats
-
8/8/2019 Perl Programming - Bslides
119/145
Perl for Linguists p.33/3
Caveats
OO programs are longer.
-
8/8/2019 Perl Programming - Bslides
120/145
OO programs are longer.
Perl for Linguists p.33/3
Caveats
OO programs are longer.
-
8/8/2019 Perl Programming - Bslides
121/145
OO programs are longer. OO programs are slower.
Perl for Linguists p.33/3
Caveats
OO programs are longer.
-
8/8/2019 Perl Programming - Bslides
122/145
OO p og a s a e o ge OO programs are slower. OO programming in perl is not orthodox OO
(lots of oddments).
Perl for Linguists p.33/3
Caveats
OO programs are longer.
-
8/8/2019 Perl Programming - Bslides
123/145
p g g OO programs are slower. OO programming in perl is not orthodox OO
(lots of oddments).
00 programming isnt intuitive for most folks.
Perl for Linguists p.33/3
Caveats
OO programs are longer.
-
8/8/2019 Perl Programming - Bslides
124/145
p g g OO programs are slower. OO programming in perl is not orthodox OO
(lots of oddments).
00 programming isnt intuitive for most folks. Unfortunately, 00 programming is essential for
some modules.
Perl for Linguists p.33/3
Tk
-
8/8/2019 Perl Programming - Bslides
125/145
Perl for Linguists p.34/3
Tk
Tk is an independent language for making
-
8/8/2019 Perl Programming - Bslides
126/145
p g g ggraphical user interfaces.
Perl for Linguists p.34/3
Tk
Tk is an independent language for making
-
8/8/2019 Perl Programming - Bslides
127/145
graphical user interfaces.
There is a special perl module so that youcan build GUIs indirectly using Tk.
Perl for Linguists p.34/3
Tk
Tk is an independent language for making
-
8/8/2019 Perl Programming - Bslides
128/145
graphical user interfaces.
There is a special perl module so that youcan build GUIs indirectly using Tk.
This module is widely available for Unix/Linuxand Windows, but not clear if its available forMacs.
Perl for Linguists p.34/3
Tk
Tk is an independent language for making
-
8/8/2019 Perl Programming - Bslides
129/145
graphical user interfaces.
There is a special perl module so that youcan build GUIs indirectly using Tk.
This module is widely available for Unix/Linuxand Windows, but not clear if its available forMacs.
If you want to write programs in Perl thatreally look like modern computer programs,then you need to use Tk.
Perl for Linguists p.34/3
GUI coding
-
8/8/2019 Perl Programming - Bslides
130/145
Perl for Linguists p.35/3
GUI coding
Tk programs use OO programming style;b i d ll bj
-
8/8/2019 Perl Programming - Bslides
131/145
buttons, windows, etc. are all objects.
Perl for Linguists p.35/3
GUI coding
Tk programs use OO programming style;b tt i d t ll bj t
-
8/8/2019 Perl Programming - Bslides
132/145
buttons, windows, etc. are all objects.
You create these objects and then yourprogram waits for the user to interact withthem.
Perl for Linguists p.35/3
GUI coding
Tk programs use OO programming style;b tt i d t ll bj t
-
8/8/2019 Perl Programming - Bslides
133/145
buttons, windows, etc. are all objects.
You create these objects and then yourprogram waits for the user to interact withthem.
makecorpus.pl makecorpusTk.pl
Perl for Linguists p.35/3
Remote computing
-
8/8/2019 Perl Programming - Bslides
134/145
Perl for Linguists p.36/3
Remote computing
CGI (Common Gateway Interface):programs that run remotely (generating
-
8/8/2019 Perl Programming - Bslides
135/145
programs that run remotely (generating
javascript and HTML: bhexp.cgi)
Perl for Linguists p.36/3
Remote computing
CGI (Common Gateway Interface):programs that run remotely (generating
-
8/8/2019 Perl Programming - Bslides
136/145
programs that run remotely (generating
javascript and HTML: bhexp.cgi) Interacting with local or remote databases
(generating sql: dbiex.pl)
Perl for Linguists p.36/3
Remote computing
CGI (Common Gateway Interface):programs that run remotely (generating
-
8/8/2019 Perl Programming - Bslides
137/145
programs that run remotely (generating
javascript and HTML: bhexp.cgi) Interacting with local or remote databases
(generating sql: dbiex.pl) Interacting with the web generally
(websearch.pl)
Perl for Linguists p.36/3
Modeling
-
8/8/2019 Perl Programming - Bslides
138/145
Perl for Linguists p.37/3
Modeling
Perl not good for computational clarity; notwell-defined
-
8/8/2019 Perl Programming - Bslides
139/145
well-defined
Perl for Linguists p.37/3
Modeling
Perl not good for computational clarity; notwell-defined
-
8/8/2019 Perl Programming - Bslides
140/145
well-defined
Perl exceptionally good at string processing
Perl for Linguists p.37/3
Modeling
Perl not good for computational clarity; notwell-defined
-
8/8/2019 Perl Programming - Bslides
141/145
well defined
Perl exceptionally good at string processing Computational tasks as string processing:
sylpars.pl
Perl for Linguists p.37/3
What now?
-
8/8/2019 Perl Programming - Bslides
142/145
Perl for Linguists p.38/3
What now?
Programming and perl hopefullydemystified. . .
-
8/8/2019 Perl Programming - Bslides
143/145
demystified. . .
Perl for Linguists p.38/3
What now?
j Programming and perl hopefullydemystified. . .
-
8/8/2019 Perl Programming - Bslides
144/145
demystified. . .j
Some ideas about what you can do with it ifyoure thinking that you need to program.
Perl for Linguists p.38/3
What now?
k Programming and perl hopefullydemystified. . .
-
8/8/2019 Perl Programming - Bslides
145/145
de yst edk
Some ideas about what you can do with it ifyoure thinking that you need to program.
k
If you already know some perl, perhaps someother ideas about what to do with what youalready know.
Perl for Linguists p.38/3