LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.

Slides:



Advertisements
Similar presentations
Arrays A list is an ordered collection of scalars. An array is a variable that holds a list. Arrays have a minimum size of 0 and a very large maximum size.
Advertisements

Perl Arrays and Lists Software Tools. Slide 2 Lists l A list is an ordered collection of scalar data. l A list begins and ends with parentheses, with.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong. Administrivia Homework 1 graded – you should have gotten an from me.
Perl Arrays and Lists Learning Objectives: 1. To understand the format and the declaration of Arrays & Lists in Perl 2. To distinguish the difference between.
Introduction to Perl. How to run perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Your program/script.
Guide To UNIX Using Linux Third Edition
LING/C SC/PSYC 438/538 Lecture 2 Sandiway Fong. Today’s Topics Did you read Chapter 1 of JM? – Short Homework 1 (submit by midnight Saturday) Some slides.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong. Continuing with Perl Homework 3: first Perl homework – due Sunday by midnight – one PDF file, by .
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
LING/C SC/PSYC 438/538 Lecture 2 Sandiway Fong. Today’s Topics Did you read Chapter 1 of JM? – Short Homework 2 (submit by midnight Friday) Today is Perl.
LING/C SC/PSYC 438/538 Lecture 3 8/30 Sandiway Fong.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Built-in Data Structures in Python An Introduction.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Introduction to Perl Part III By: Bridget Thomson McInnes 6 Feburary 2004.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong. Administrivia Homework 2 graded.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
Perl Chapter 5 Hashes. Outside of world of Perl, know as associative arrays Also called hash tables Perl one of few languages that has hashes built-in.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong. Adminstrivia Homework 4 not yet graded …
Perl COEN 351  Thomas Schwarz, S.J Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Topic 3: Lists and arrays CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 3, pages 40-55, 86-91, Programming Perl 3rd edition.
Perl Scripting III Arrays and Hashes (Also known as Data Structures) Ed Lee & Suzi Lewis Genome Informatics.
Week Four Agenda Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines.
LING 408/508: Programming for Linguists Lecture 27 December 9 th.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
Arrays and Lists. What is an Array? Arrays are linear data structures whose elements are referenced with subscripts. Just about all programming languages.
CSC 4630 Perl 2 adapted from R. E. Beck. I/O and Arithmetic Form pairs of programmer/investigator/discover Exercise 1. Write a program that prompts the.
Chapter 17 Arrays Perl to denote an array, for = (10, 20, 30, 50); Array subscripts are number from 0. Array elements require scalar.
Web Database Programming Using PHP
Python Variable Types.
System Administration Introduction to Scripting, Perl Session 5 – Fri 23 Nov 2007 References: Perl man pages Albert Lingelbach, Jr.
© 2016 Pearson Education, Ltd. All rights reserved.
Containers and Lists CIS 40 – Introduction to Programming in Python
Web Database Programming Using PHP
Command Line Arguments
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 5 Sandiway Fong.
What is Bash Shell Scripting?
Chapter 14 Introduction to Ruby.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong.
Perl Variables: Array Web Programming.
Introduction to Python
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 10 Sandiway Fong.
An Introduction to Perl
Data Structures – 1D Lists
LING/C SC/PSYC 438/538 Lecture 12 Sandiway Fong.
Perl I/O Learning Objectives:
MSIS 655 Advanced Business Applications Programming
Python Primer 1: Types and Operators
Chapter 11 Introduction to Programming in C
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.
CHAPTER 4: Lists, Tuples and Dictionaries
Chapter 11 Programming in C
Useful functions.
Class code for pythonroom.com cchsp2cs
LING/C SC/PSYC 438/538 Lecture 5 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 7 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 12 Sandiway Fong.
Presentation transcript:

LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong

Exercises If you’re new to programming or Perl, read and run all the examples! Advance preparatory reading: Chapter 2 of the textbook we’ll be using Perl’s regular expression (regex) engine for this

Perl Wierdness Variable types: Every variable type has its own namespace. This means that $foo and @foo are two different variables. It also means that $foo[1] is a part of @foo, not a part of $foo. This may seem a bit weird, but that's okay, because it is weird.

Perl Wierdness Reading Perl code (perldata) aloud: Larry Wall was a linguist … The '$' symbol works semantically like the English word "the" in that it indicates a single value is expected. Entire arrays (and slices of arrays and hashes) are denoted by '@', which works much like the word "these" or "those" does in English, in that it indicates multiple values are expected. Also: Entire hashes are denoted by '%’… (no translation) In addition, subroutines are named with an initial '&', though this is optional when unambiguous, just as the word "do" is often redundant in English.

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 -2..-1 A note on output: print @a zeroonetwothreefour print “@a” zero one two three four controlled by system variable $” default value: a space

Perl Arrays Literal: Access: Index of last element: Coercion @ARRAY = ( … , … , …) (round brackets; comma separator) Access: $ARRAY[INDEX] (zero-indexed; negative indices ok; slices ok) Index of last element:  $#array (a scalar) Coercion @ARRAY = number of elements in scalar context Built-in arrays: @ARGV (command line arguments) @_ (sub(routine) arguments)

Perl Arrays There’s a special array called @ARGV Getting user input into your program: @ARGV C programming language: int argc, char *argv[] Shell script: $0 $1 $2 .. ($#)

Perl Arrays Built-in functions: sort @ARRAY; reverse @ARRAY; push @ARRAY, $ELEMENT; pop @ARRAY; shift @ARRAY; unshift @ARRAY, $ELEMENT, splice @ARRAY, $OFFSET, $LENGTH, $ELEMENT Note: $ELEMENT above can also be @ARRAY

Perl Arrays by default sort works according to the ASCII chart, character by character asciitable.com

Perl Arrays Numeric sort? Idea: to pass an inline comparison function as parameter… Note: fc (fold case) use feature 'fc';

Perl Hashes

Perl Hashes Notes on arrays and hashes arrays are indexed using integers hashes are like arrays with user-defined indexing (aka associative array or hash table or dictionary (Python)) initialization (use list notation (or shortcut): round brackets and commas) @a = (“zero”, “one”, “two”, “three”, “four”); %h = (“zero”, 0, “one”, 1, “two”, 2, “three”, 3, “four”, 4); (key/value pairs) access to individual elements (square brackets vs. curly braces) $a[1] “one” $h{zero} 0 Shortcut:

Perl Hashes Notes on arrays and hashes output print @a zeroonetwothreefour print "@a" zero one two three four print %h three3one1zero0two2four4 (note: different order) print "%h" %h (literal, no interpolation done)

More on Hash tables Example: Output: Unique key constraint: