Chapter 17 Arrays Perl to denote an array, for = (10, 20, 30, 50); Array subscripts are number from 0. Array elements require scalar.

Slides:



Advertisements
Similar presentations
Perl Practical Extration and Reporting Language An Introduction by Shwen Ho.
Advertisements

1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 5 List Variables and Loops.
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.
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
Bioinformatics Lecture 7: Introduction to Perl. Introduction Basic concepts in Perl syntax: – variables, strings, input and output – Conditional and iteration.
COS 381 Day 19. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
Sorting. Simple Sorting As you are probably aware, there are many different sorting algorithms: selection sort, insertion sort, bubble sort, heap sort,
Operators. Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable.
CS 898N – Advanced World Wide Web Technologies Lecture 7: PERL Chin-Chih Chang
Chapter 8 Arrays and Strings
Programming Logic and Design Fourth Edition, Comprehensive
2.1 Lists and Arrays Summary of 1 st lesson Single quoted and double quoted strings Backslash ( \ ) – the escape character: \t \n Operators:
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Practical Extraction & Report Language PERL Joseph Beltran.
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
Chapter 8 Arrays and Strings
Session 7 JavaScript/Jscript: Arrays Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Perl By Gabe and Ted. History Perl was created by Larry Wall while working at NASA’s Jet Propulsion Labs. Larry Wall also created patch which is in widespread.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Perl Practical(?)‏ Extraction and Report Language.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
Class 2Intro to Databases Goals of this class Include & Require in PHP Generating Random Numbers in PHP Arrays – Numerically Indexed and Associative Program.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
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.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
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.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
More Perl Data Types Scalar: it may be a number, a character string, or a reference to another data type. -the sigil $ is used to denote a scalar(or reference)
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
 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.
Perl Scripting III Arrays and Hashes (Also known as Data Structures) Ed Lee & Suzi Lewis Genome Informatics.
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
Arrays and Lists. What is an Array? Arrays are linear data structures whose elements are referenced with subscripts. Just about all programming languages.
Perl Chapter 3 Conditional statements. Control Expressions Control expressions – interpreted as T/F (evaluated as strings or numbers) – simple, relational,
Chapter 22 Selection and Iteration if ( Boolean Expression ) true statement ; else false statement ; OperatorMeaning ! Logical not < Less than
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
Chapter 18 The HTML Tag
Chapter 6: Using Arrays.
Microsoft Visual Basic 2005: Reloaded Second Edition
© 2016 Pearson Education, Ltd. All rights reserved.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Chapter 5 - Control Structures: Part 2
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.
Perl Variables: Array Web Programming.
Introduction to Python
Control Structures: if Conditional
Introduction to Perl Jarrad Battaglia.
Perl Variables: Hash Web Programming.
CIT 383: Administrative Scripting
An Introduction to Perl
Control Structures: for & while Loops
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: part II hashes, foreach control statements, and the split function By: Kevin Walton.
String and Lists Dr. José M. Reyes Álamo.
Logical Operations In Matlab.
Relational Operators.
The Selection Structure
INTRODUCTION to PERL PART 1.
Karan Thaker CS 265 Section 001
Presentation transcript:

Chapter 17 Arrays Perl to denote an array, for = (10, 20, 30, 50); Array subscripts are number from 0. Array elements require scalar notation, for example, $x[0]. To find the size of an array, assign it to a scalar, for example $size

Chapter 17 Relational Operators Numeric String Meaning < lt less than <= le less than or equal > gt greater than >= ge greater than or equal == eq equal != ne not equal cmp signed comparison Perl uses separate operators for numbers and strings

Chapter 17 Logical Operators Operator Meaning ! not && and || or The logical operators are arranged in order of precedence.

Chapter 17 Iteration Statments Perl contains four iteration statements. Each requires a block of code for the body. The statements are: The for Statement The while Statement The until Statement The foreach Statement

Chapter 11 The for Statement The for statement is typically used for counting. The structure of the statement is: for ( InitialExpression ; Test Expression ; Change Expression ) { Statement; } Braces are required in Perl.

Chapter 17 The for Statement for ($i=0; $i < $size; $i++) { print "$barnyard[$i] = ("pig", "ox", "horse", "chicken"); $size Creating the barnyard array. Print the array with a for statement.

Chapter 11 The while Statement The while statement is used for error loops or to process the key-value pairs in a hash. The structure of the statement is: while ( Expression ) { Statement; } Braces are required in Perl.

Chapter 17 The while Statment $i = 0; while ($i < $size){ print "$barnyard[$i] \n"; $i++; } Printing the barnyard array with a while statement.

Chapter 11 The until Statement The until statement executes the code in the body until the expression becomes true. This statement is unique to Perl. Its structure is: until ( Expression ) { Statement; } Braces are required in Perl.

Chapter 17 The until Statment $i = 0; until ($i == $size){ print "$barnyard[$i] \n"; $i++; } Printing the barnyard array with an until statement.

Chapter 11 The foreach Statement The foreach statement automates array processing. This statement is also unique to Perl. Its structure is: foreach $ variable array ) { Statement; } Braces are required in Perl.

Chapter 17 The foreach Statment foreach { print "$animalBR>\n";} Printing the barnyard array with a foreach statement.

Chapter 17 Perl Array Functions Function name = sort{ order } array Sort name = array Reverse name array [ start…stop ] Slice name array [ i, j, k ] Slice name = grep(/ pattern array ) Pattern Match.. array, $ elem ) Add to right end. array, $ elem ) Add to left end. $ name = array Remove from right end. $ name = array Remove from left end.

Chapter 17 References A reference is a scalar that holds the address of a variable. References

Chapter 17 References To create a reference, use \ = \$x; To dereference, that is, to obtain the contents of the “pointed to” variable, use $. For example, print “$$x_ref”; prints the contents of $x not the address.

Chapter 17 = ( [1,2], [3,4], [5,6]); A matrix (or two-dimensional array) is an array that contains references to one dimensional arrays as = = = = Anonyomous references Named references

Chapter 17 Hashes A hash uses a randomizing function to store key-value pairs. Perl uses % to denote a hash. Hash elements are accessed by their keys. Scalar notations is used. There are two forms for creating a hash.

Chapter 17 Creating Hashes %animals = (“dogs”, “Hunde”, “cats”, “Katzen”); %animals = (“dogs”=> “Hunde”, “cats”=> “Katzen”); Either of these techniques will create a hash.

Chapter 17 Hash Operations $animals{“horses”} = “Pherde”; $german = $animals{“dogs”}; Adds horses to the hash. Extracts the german word for dogs. Deletes dogs from the hash. delete $animals{“dogs”};

Chapter 17 Printing the Keys in a Hash foreach $key = (keys %animals) { print “$key \n”;} To print all of the keys in a hash,we use the keys function.

Chapter 17 Printing the Values in a Hash To print all of the values in a hash,we use the values function. foreach $value = (values %animals) { print “$value \n”;}

Chapter 17 Printing the Key-Value Pairs while(($english, $german) = each (%animals)) { print “$english = $german \n”;} To print all of the key-value pairs we use the each function and a while statement.

Chapter 17 An Array of = ( {#0 english => “zero”, german => “null”,}, ); An array of hashes is an array where each element is a hash. The array is created as a list. Each element is a hash, so we use hash notation.

Chapter 17 An Hash of Hashes %weekdays = (‘Monday’ => { german => “Montag”, tibetan => “sa da wa”,}, ); An hash of hashes is a hash where the values are hashes.

Chapter 17 Accessing Advanced Structures To access an array of hashes, we use an index and a key, for example: $english = $numbers[0]{english}; To access a hash of hashes, we use two keys, for example: $german = $weekday {‘Monday’}{german};