Download presentation
Presentation is loading. Please wait.
Published byRitva Karvonen Modified over 5 years ago
1
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong
2
Today's Topics A note on UTF-8 and PowerShell in Windows 10
Review Homework 6 Homework 7
3
Unicode and PowerShell
Windows 10: Default console is not UTF-8 and uses ancient codepage technology (437 = US)! Set it to UTF-8. Note codepage change. Unfortunately, it now understands UTF-8, but fails to print the character!
4
Unicode and PowerShell
Right-click menu bar Properties > Font Consult soft.com/en- us/typography/fon t-list/ for the codepages that each font supports
5
Unicode and PowerShell
Default console font is actually called Consolas Even the Lucida Console font family is limited.
6
Unicode and PowerShell
Pick a known Japanese font licensed by Microsoft from Ricoh (Japan). MS Mincho
7
Unicode and PowerShell
Et voilà!
8
Homework 6 Review Question 1: what's the difference between a) and b)?
= 4 x 4; = (4) x 4; perl -le = 4 x 4; print $#a; print 4444 perl -le = (4) x 4; print $#a; print 3
9
Homework 6 Review read https://perldoc.perl.org/functions/split.html
Question 2: what does split do here for a) vs. b)? = split " ", 'this is a sentence.'; = split //, 'this is a sentence.'; perl -le = split \" \", 'this is a sentence.'; print \$#a; print 3 this is a sentence. perl -le = split //, 'this is a sentence.'; print \$#a; print 18 t h i s i s a s e n t e n c e .
10
Homework 7 Read https://en.wikipedia.org/wiki/Disemvoweling
Q1: Write a Perl program to remove vowels a, e, i, o, u from words typed into the command line. (Don't worry about y.) Hint: use split from HW 6 Question 2 Example:
11
Homework 7 A possible template for your code exists $vowel{$char}
12
Homework 7 Q2: Suppose we modified the program to print underscores instead of deleting vowels. Which quote below do you find easier to read? Translate the quote back into regular English orthography. All h_m_n b__ngs _r_ b_rn fr__ _nd _q__l _n d_gn_ty _nd r_ghts. Th_y _r_ _nd_w_d w_th r__s_n _nd c_nsc__nc_ _nd sh__ld _ct t_w_rds _n_ _n_th_r _n _ sp_r_t _f br_th_rh__d. All hmn bngs r brn fr nd ql n dgnty nd rghts. Thy r ndwd wth rsn nd cnscnc nd shld ct twrds n nthr n sprt f brthrhd. Due date: Monday night. One PDF file. Submit your code and example runs.
13
Python list ranges Perl has a range operator: ..
less powerful in some ways, more powerful in others
14
Perl list ranges Python equivalent:
for i in range(1, ): # code iterates setting $. (default variable) from 1, 2, ..,
15
Perl: useful string functions
chomp (useful with file I/O) vs. chop Note: multiple spaces ok with " " variant
16
Python: .split() string (sentence) splitting is an important part of text processing. Oftentimes we split strings by a regular expression: import re re.split(regex,s)
17
Perl: useful string functions
Transliterate: tr/matchingcharacters/replacementcharacters/modifiers modifiers are optional:
18
Perl: useful string functions
Perl doesn't have a built-in trim-whitespace-from-both-ends-of-a- string function. Can be mimicked using regex (more later) Python:
19
Python: strings Many methods that work on lists also work on strings
20
Python: strings List comprehension:
sentence = ['A', 'big', 'cat', 'in', 'Tucson'] [x.lower() for x in sentence] Suppose we want to use .endswith() in a list comprehension: Reference:
21
Python: strings conditional list comprehensions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.