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 email.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
A Guide to Unix Using Linux Fourth Edition
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong. Administrivia Homework 1 graded – you should have gotten an from me.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
Introduction to Computers and Programming Lecture 15: Arrays Professor: Evan Korth New York University.
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.
Sorting. Simple Sorting As you are probably aware, there are many different sorting algorithms: selection sort, insertion sort, bubble sort, heap sort,
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/28.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Guide To UNIX Using Linux Third Edition
LING/C SC/PSYC 438/538 Lecture 5 9/8 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 5 Sandiway Fong. Today’s Topics File input/output – open, References Perl modules Homework 2: due next Monday by midnight.
PERL Variables and data structures Andrew Emerson, High Performance Systems, CINECA.
Lists in Python.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
LING/C SC/PSYC 438/538 Lecture 3 8/30 Sandiway Fong.
Perl Language Yize Chen CS354. History Perl was designed by Larry Wall in 1987 as a text processing language Perl has revised several times and becomes.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
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.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
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 Basics. sh-bang !!!! Every perl program starts with a sh-bang line #!/usr/bin/perl # hello.pl printf “Hello, world!\n”; printf STDOUT “Hello, world!\n”;
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.
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 …
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
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.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong. Homework 4 Submit one PDF file Your submission should include code and sample runs Due date Monday 21.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
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.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
Web Database Programming Using PHP
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Web Database Programming Using PHP
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 5 Sandiway Fong.
Introduction to Python
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong.
Introduction to Python
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong.
Perl I/O Learning Objectives:
LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.
Karan Thaker CS 265 Section 001
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

Continuing with Perl Homework 3: first Perl homework – due Sunday by midnight – one PDF file, by to me Learn Perl – Books… – Online resources we begin with...

Perl arrays and hashes Scalars: – strings, numbers (integers, floating point numbers), references Arrays: – Idea: list of scalars – Access by index: 0,1,2,… Hash: – Like an array except access not through a numeric index – Use user-specified keys %variable different namespaces: %apple are different data structures and can co-exist simultaneously different namespaces: %apple are different data structures and can co-exist simultaneously

Perl Arrays Arrays: – Idea: list of scalars – Access by index: 0,1,2,… Notes on output print one two three four controlled by system variable $” default value: a space controlled by system variable $” default value: a space negative indices count from the end $#array (index of last (can have scalar interpretation) negative indices count from the end $#array (index of last (can have scalar interpretation)

Perl Arrays Forgot to mention last time, a special array Getting user input into your C programming language: int argc, char *argv[] Shell script: $0 $1 $2..( $# )

Perl Hashes

Notes on arrays and hashes – arrays are indexed from 0,1,2,3… – hashes are like arrays with user-defined indexing (aka associative array or hash table) – initialization (use list notation (or shortcut): round brackets and = (“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 zeroonetwothreefour print 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:

More on Hash tables Last time: – Exercise: try to write the code for looking up keys based off a value – Anyone try it? An opportunity to use a loop Extras:

Perl arrays List operations:

Perl Arrays Last time: – 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) from Perl 5.16 onwards only

Perl Hashes Sorting with a hash sort byage keys %age Let sort by fruit, by color, ascending, descending…

Implicit Coercion Example: – the following program prints Equal! – == is the numeric equality comparison operator my $one_string = “1”; my $one_number = 1; if ($one_string == $one_number) { print “Equal!\n” } else { print “Different!\n” } Example: – the following program prints 3 is my number –. is the string concatenation operator = qw(one, two, three); my $string is my number”; print “$string\n”; Perl features implicit coercion of data types

Implicit Coercion print “4” * 4 16 (strange behavior if you’re coming from Python) print “4” x 4(“x” is the repetition operator) = (4) x 4(in list context) (4, 4, 4, 4)

Homework 3 Check your understanding… Most frequent names (2000 US Census) Smith Johnson Williams Brown Jones Miller Davis Garcia Rodriguez Wilson Martinez Anderson Taylor Thomas Hernandez Moore Martin Jackson Thompson White Put them in a hash 2.Sort by name, sort by frequency 3.ascending and descending 4.Write code to count the number of names with frequency > some number, e.g. 1,000,000 – supplied on the command line 5.perl prnames.perl name|frequency ascending|descending 6.perl prnames.perl count number i.e. computes item 4. 7.Print out the results (names…)