Download presentation
Presentation is loading. Please wait.
1
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong
2
Administrivia Today's Topics
Quick Homework 4 graded (you should have an from me) Today's Topics Terminal log from last time A note on Windows 10 and quoting Review of Homework 4 Continuing on with perlintro (scalars and arrays)
3
Terminal: from last time
~$ perl test.perl Can't open perl script "test.perl": No such file or directory ~$ pwd /Users/sandiway ~$ cd Desktop Desktop$ pwd /Users/sandiway/Desktop Desktop$ perl test.perl Hello, worldDesktop$ perl test.perl Hello, world Hello, world\nDesktop$ perl test.perl Desktop$ perl test.perl Hello, world Desktop$ perl -e 'print "Hello, World"' Hello, WorldDesktop$ perl -e 'print "Hello, World\n"' Hello, World Desktop$ perl -le 'print "Hello, World"' Name "main::Hello" used only once: possible typo at test.perl line 3. print() on unopened filehandle Hello at test.perl line 3.
4
Terminal: from last time
Desktop$ perl test.perl Global symbol "$Hello" requires explicit package name (did you forget to declare "my $Hello"?) at test.perl line 3. Global symbol "$Hello" requires explicit package name (did you forget to declare "my $Hello"?) at test.perl line 4. Execution of test.perl aborted due to compilation errors. This is a stringDesktop$ perl test.perl This is a string\nDesktop$ perl test.perl This is a string Desktop$ perl test.perl Name "main::Hello" used only once: possible typo at test.perl line 3. Name "main::Helo" used only once: possible typo at test.perl line 4. Use of uninitialized value $Helo in string at test.perl line 4.
5
Terminal: from last time
Desktop$ perl test.perl Global symbol "$Hello" requires explicit package name (did you forget to declare "my $Hello"?) at test.perl line 3. Global symbol "$Helo" requires explicit package name (did you forget to declare "my $Helo"?) at test.perl line 4. Execution of test.perl aborted due to compilation errors. Desktop$ MacOS: aquamacs editor TextEdit Linux: nano emacs Windows 10: Notepad
6
Terminal: from last time
Windows 10 command prompt single quotes not recognized as quotes double quotes can be used inside the (initial) double quotes, everything will be passed to Perl: you can use single quotes you can escape double quotes, i.e. \" to get a double quote.
7
Terminal: from last time
You can also use PowerShell in Windows 10: both single and double quotes can be used as quoting characters in the shell. Inside the initial quotes, you can escape any quotes that need to be passed to Perl.
8
Terminal: from last time
~$ cd Desktop Desktop$ python3 Python (v3.7.3:ef4ec6ed12, Mar , 16:52:21) [Clang 6.0 (clang )] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print("Hello, World") Hello, World >>> print "Hello, world\n"; File "<stdin>", line 1 print "Hello, world\n"; >>> SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello, world\n")? >>> print "Hello, world\n"; File "<stdin>", line 1 print "Hello, world\n"; ^ >>> >>> print("Hello, World") Hello, World >>> print('Hello, World') >>> print('Hello, World\n') >>> print('Hello, World\n\n\n\n\n')
9
Homework 4 Review 1. Commas are important people.
Q2: Run the these two sentences on the Berkeley Parser. Critique the parse. ( Q3: Compare with the Google Parser. Critique the dependency parses. (
10
Homework 4 Review Berkeley Parser
11
Homework 4 Review Google Parser
ATTR - link between a verb like 'be/seem/appear' and its complement attr has been removed as a relation. attr was a relation intended for the complement of a copular verb such as “to be”, “to seem”, “to appear”. Mainly, it was used for WHNP complements. (The relation attr was meant to stand for “attributive” but that was arguably a misuse of the word.)
12
Homework 4 Review Periods are important, people! Compare!
13
Homework 4 Review Capitalization is important, people! Compare!
14
print as a statement vs. function
Perl Python3 Same behavior, different assumptions about end of line (\n) from these two programming languages "\" is the escape character Note also the differences in syntax: (..) in Python3, no parentheses (needed) in Perl ; need to separate the statements in Perl, none in Python
15
Perl vs. Python3 Scalars: (basically things that take up one 32/64 bit word of memory) variables begin with ($) - no such type requirement in Python Numbers (integer, floating point) Python includes complex numbers (cmath library) Strings (double ".." or single quoted '..') References (pointers to (non-)scalars)
16
Perl vs. Python3 Variable interpolation Perl: Python3: Python2.7:
print "My name is $name\n"; print "My name is \$name\n"; print 'My name is \$name\n'; Python3: print("My name is", name) Python2.7: Note: white spacing
17
perlintro: Arrays like a simple ordered list… (in Python, we use a list) Literal: @ARRAY = ( … , … , …) (round brackets; comma separator) Python: array = [… , … , … ] Access: $ARRAY[ INDEX] (zero-indexed; negative indices ok; slices ok) Python: array[index] Index of last element: $#array (a scalar) Python: len(array)-1 array[-1] Coercion @ARRAY = number of elements in scalar context Python: len(array) Built-in functions: $ELEMENT; $ELEMENT, $OFFSET, $LENGTH, $ELEMENT $ELEMENT above can Python: array.sort(), array.reverse() Built-in arrays: @ARGV (command line arguments) @_ (sub(routine) arguments)
18
perlintro Notes from the tutorial:
semicolon (;) is not always necessary Command separator semantics vs. end of command (termination) token Best practice? Terminate every command with a semicolon Variable types: Every variable type has its own namespace. This means that $foo are two different variables. It also means that $foo[1] is a part not a part of $foo. This may seem a bit weird, but that's okay, because it is weird.
19
Perl Arrays Arrays: A note on output: Idea: list of scalars
like a simple ordered list (cf. Python lists) access by index: 0,1,2,… negative indices count from the end A note on output: zeroonetwothreefour print zero one two three four controlled by system variable $" default value: a space
20
perlintro: Perl Arrays
like a simple ordered list… (in Python, we use a list) Literal: @ARRAY = ( … , … , …) (round brackets; comma separator) Python: array = [… , … , … ] Access: $ARRAY[ INDEX] (zero-indexed; negative indices ok; slices ok) Python: array[index] Index of last element: $#array (a scalar) Python: len(array)-1 (access: array[-1])
21
Shell quoting Bash shell (MacOS, Linux): cf. Windows 10 slide earlier
manual: can't write: perl -e print
22
Shell quoting Bash shell (MacOS, Linux): can write:
perl -e print
23
perlintro: Perl Arrays
like a simple ordered list… (in Python, we use a list) Coercion @ARRAY = number of elements in scalar context Python (no coercion): len(array) Built-in functions: $ELEMENT; $ELEMENT, $OFFSET, $LENGTH, $ELEMENT $ELEMENT above can Python: array.sort(), array.reverse(), NO push (use array.append() instead), array.pop(), No shift/unshift etc… Built-in arrays: @ARGV (command line arguments) @_ (sub(routine) arguments)
24
perlintro: Perl Arrays
Similar to pop/push, but operates at the left end of the array Python doesn't have these defined but can be simulated via slicing and concatenation: array[1:] list + array
25
perlintro: Perl Arrays
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.