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.

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

Container Types in Python
Arithmetic Expressions Infix form –operand operator operand 2+3 or a+b –Need precedence rules –May use parentheses 4*(3+5) or a*(b+c)
Online Counseling Resource YCMOU ELearning Drive… School of Architecture, Science and Technology Yashwantrao Chavan Maharashtra Open University, Nashik.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Dynamic Arrays Lecture 4. Arrays In many languages the size of the array is fixed however in perl an array is considered to be dynamic: its size can be.
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.
DICTIONARIES. The Compound Sequence Data Types All of the compound data types we have studies in detail so far – strings – lists – Tuples They are sequence.
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
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.
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
Lists/Tuples. Example Write a program to keep track of all students’ scores on exam 1. Need a list of everyone’s score Use 14 doubles What about next.
Lists/Tuples. Example Write a program to keep track of all students’ scores on exam 1. Need a list of everyone’s score Use 14 doubles What about next.
Perl File I/O and Arrays. File I/O Perl allows to open a file to read, write, or append As well as pipe input or output to another program. —We get to.
JavaScript, Third Edition
2ex.1 Lists and Arrays. 2ex.2 Comments on exercises Always run your script with “ perl -w ” and take care of all warnings  submitted scripts should not.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
CS0007: Introduction to Computer Programming Introduction to Arrays.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 8: Perl Basics Fundamentals of Web Programming.
CS 100: Roadmap to Computing Fall 2014 Lecture 01.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
Lists in Python.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
Print 'Hello world.'; Tren Griffith. Outline:  Perl introduction  Scalar Data  Variables  Operators  Control Structures  Input  Lists and Arrays.
CPTG286K Programming - Perl Chapter 3: Arrays and List Data.
Chapter 9: Functional Programming in a Typed Language.
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.
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.
10. Python - Lists The list is a most versatile datatype available in Python, which can be written as a list of comma-separated values (items) between.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
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.
CPTG286K Programming - Perl Chapter 4: Control Structures.
CPTG286K Programming - Perl Chapter 5 & 6: Hashes & Basic I/O.
Loops & List Intro2CS – week 3 1. Loops -- Motivation Sometimes we want to repeat a certain set of instructions more than once. The number of repetitions.
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
 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.
Topic 3: Lists and arrays CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 3, pages 40-55, 86-91, Programming Perl 3rd edition.
How do you do the following? Find the number of scores within 3 points of the average of 10 scores? What kind of a tool do you need? Today’s notes: Include.
Perl Scripting III Arrays and Hashes (Also known as Data Structures) Ed Lee & Suzi Lewis Genome Informatics.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
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];
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming javascript arrays.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Programming Perl in UNIX Course Number : CIT 370 Week 2 Prof. Daniel Chen.
Arrays and Lists. What is an Array? Arrays are linear data structures whose elements are referenced with subscripts. Just about all programming languages.
2000 Copyrights, Danielle S. Lahmani Foreach example = ( 3, 5, 7, 9) foreach $one ) { $one*=3; } is now (9,15,21,27)
CSC 4630 Perl 3 adapted from R. E. Beck. Problem But we worked on it first: Input: Read from a text file named in a command line argument Output: List.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
String and Lists Dr. José M. Reyes Álamo.
Definition of the Programming Language CPRL
Containers and Lists CIS 40 – Introduction to Programming in Python
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
MATLAB: Structures and File I/O
Chapter 14 Introduction to Ruby.
Perl Variables: Array Web Programming.
Data Structures – 1D Lists
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
String and Lists Dr. José M. Reyes Álamo.
CHAPTER 4: Lists, Tuples and Dictionaries
INTRODUCTION to PERL PART 1.
Class code for pythonroom.com cchsp2cs
Presentation transcript:

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 user for a number, representing the radius of a sphere. The program prints out the volume of the sphere. (Note: B to 10 significant figures is )

Operator x Exercise 2. Write a program that prompts the user for a (short) string and a positive integer and outputs the string repeated the number of times indicated. For example, with input ha 4 the program gives hahahaha Exercise 3. Modify the previous program to print the output on separate lines, one for each instance of the input string.

Arrays in PERL Look much like lists from LISP except elements must be scalars. Size does not need to be specified initially. Use length as a descriptive measure. Values can be specified by list literals.

List Literals Several forms: –Values separated by commas enclosed in parentheses. (3.4, 5.6, 8.1, 0) (“fred”, “george”, 1, 3) –Values can be determined by expressions, which are evaluated when the literal is used. ($a, $b, $a+$b, $a-$b)

List Literals (2) –The empty list, denoted by () –Values generated by the list constructor operator denoted by.. (1.. 5) generates the list (1, 2, 3, 4, 5) ( ) generates the list (2.2, 3.2, 4.2, 5.2) (0.. 4, 8, 9) generates the list (0, 1, 2, 3, 4, 8, 9) –Values generated by the quote word function qw(alice bob chuck) generates the list (“alice”, “bob”, “chuck”)

Array Variable Holds a single list value, meaning zero or more scalar values. Name starts (rather than $). Can be treated as a whole by certain array operators and array functions. (Similar to LISP or APL)

Array Operators Assignment = # Appends 8 as the first element = qw(one two) = (4, 8, 9) # have the value (4, 5, “one”, “two”, 8, 9) –($a, $b, $c) = (1, 2, 3) # Simultaneous scalar assignment –($a, $b) = ($b, $a) # Swap values (temporary location is hidden)

Array Operators (2) Fancier assignment statements –Embedded array = ($a, $b, $c) $d becomes the value of becomes ($b, $c) –Array sharing, array decomposition $e becomes the first becomes

Array Operators (3) –Length mismatches Too many on right: excess discarded Too many on left: excess set to undef –Length function: implicit $a # sets $a to –Compare with = ($a)

Array Element Access Index origin is 0 = (1..5) $fred[2] is 3 Slice: a subarray chosen by an index list = is (3,4,5)

Array Element List (2) More slices makes the first three elements equal to $fred[1] = (7,8,9) = (2,1,0) = is (9,8,7)

Array Element List (3) $#fred is the index value of the last element So, $fred[$#fred] is the value of the last element And so is $fred[-1] since negative indices count backwards from the end, starting at -1.

Arrays as Stacks push “new”) is equivalent = “new”) $a = removes the last value and assigns it to $a. Right is no better than left unshift “new”) is equivalent =

Arrays as Stacks (2) $a = assigns the first element to $a and removes it

More Array Functions reverse sort chomp