Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.

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

Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
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.
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 I/O Learning Objectives: 1. To understand how to perform input from standard Input & how to process the input 2. To understand how to perform input.
Programming and Perl for Bioinformatics Part III.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
Bioinformatics Lecture 7: Introduction to Perl. Introduction Basic concepts in Perl syntax: – variables, strings, input and output – Conditional and iteration.
CS 898N – Advanced World Wide Web Technologies Lecture 8: PERL Chin-Chih Chang
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
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.
Practical Extraction & Report Language Picture taken from
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
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.
I/O while ($line= ){ #remove new line char \n chomp($line); if($line eq “quit”){ exit(1); } while ( ){ #remove new line char \n chomp($_); if($_ eq “quit”){
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.
Guide To UNIX Using Linux 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.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Introduction to Perl Part III By: Cedric Notredame Adapted from (BT McInnes)
Practical Extraction & Report Language PERL Joseph Beltran.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
CPTG286K Programming - Perl Chapter 3: Arrays and List Data.
Meet Perl, Part 2 Flow of Control and I/O. Perl Statements Lots of different ways to write similar statements –Can make your code look more like natural.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to Perl Giorgos Georgakilas Graduated from C.E.I.D.Graduated from C.E.I.D. M.Sc. degree in ITMBM.Sc. degree in ITMB Ph.D. student in DIANA-LabPh.D.
Books. Perl Perl (Practical Extraction and Report Language) by Larry Wall Perl 1.0 was released to usenet's alt.comp.sources in 1987 Perl 5 was released.
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
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.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
5 1 Data Files CGI/Perl Programming By Diane Zak.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
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 12/13/ Introduction to Perl - Strings, Truth and Regex Introduction to Perl Session 2 · manipulating.
CPTG286K Programming - Perl Chapter 5 & 6: Hashes & Basic I/O.
A Few More Functions. One more quoting operator qw// Takes a space separated sequence of words, and returns a list of single-quoted words. –no interpolation.
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
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.
Working with Loops, Conditional Statements, and Arrays.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
1 PERL Functions. 2 Functions Functions also called subroutines are “free flowing”. The returned value from a function can be interpreted in many different.
Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp
2.1 Lesson 2: Scalar Functions and Arrays “Perl programming is an empirical science!” - Larry Wall.
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
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.
The Scripting Programming Language
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
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.
Strings … operators Up to now, strings were limited to input and output and rarely used as a variable. A string is a sequence of characters or a sequence.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
Chapter 17 Arrays Perl to denote an array, for = (10, 20, 30, 50); Array subscripts are number from 0. Array elements require scalar.
Perl Programming Language Design and Implementation (4th Edition)
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 Perl Jarrad Battaglia.
Perl Variables: Hash Web Programming.
Basic Input/Output Web Programming.
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.
Perl I/O Learning Objectives:
Presentation transcript:

Perl Variables: Array Web Programming1

Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► = (“Mary”,”Tom”); ► holds a list of scalars ► $array1[0]=“Mary”; $array1[1]=“Tom”; Associative array (i.e. hash) ► e.g. %hash1 = (“Mary”,”F”,”Tom”,”M”); ► holds key-value scalar pairs ► $hash{“Mary”}=“F”; $hash{“Tom”}=“M”; Web Programming 2

Array and List List ► a sequence of scalar values (i.e. elements) e.g. (1, 2, 3), (“a”, ”b”, ”c”), (1, ”a”, 2.3, 4) Array ► a Perl variable that holds a list data = (1, 2, 3); ► an array element is a scalar variable e.g. $array[0]; Web Programming 3

Array Syntax Array Name ► first character must ► second character must be a letter. ► can consist of only letters, digits, or underscore ► case-sensitive ► can be as long as you want (within reason) Array Elements ► $array_name[$index] ► array index goes from 0 to (array length -1) = (“cat”, ”dog”, “pig”); $array[0] is “cat”, $array[1] is “dog”, $array[2] is “pig” array length ► number of elements in an array ► $array_length Web Programming 4

Array: Value Assignment Assigning values to an array variable = (element0, element1,..); ► an element can be a constant, a variable, an expression, or a list range e.g. 1..5, “a”..“z” ► = (“one”, 2, “three”, “four”, = (1, = (1, 1+1, $a.$b, = = ( ) Array values in a conditional expression ► if false if a null array, true otherwise  Example scriptExample script Web Programming 5

Array Elements array element ► $array[index] index of the last element ► 1 less than array length ► $#array last element ► $array[-1] ► $array[$#array] ► Web Programming 6

Printing Arrays ► prints all elements concatenated together. ► print prints elements separated by a space (default list separator). the list separator ($”) can be set to a different value. ► foreach $item { print “$item\n”; } ► For ($i=0; $i <=$#array; $i++) { print “$array[$i]\n”; }  Example scriptExample script Web Programming 7

String to Array Conversion $string = join ► concatenates elements using $separator $string = ► concatenates elements using “ = split (/$separator/, $string); ► splits $string by $separator  Example scriptExample script Web Programming 8

Array = sort ► sorts = reverse ► reverses the order of array elements $first = shift ► remove and return the first element $last = pop ► remove and return the last element unshift $item); ► add $item to the start push $item); ► add $item to the end chop ► chops the last character of each element chomp ► removes the last character of each element if it is a newline character  Example scriptExample script Web Programming 9

Reading Input into Arrays Reading from STDIN = ;  Example scriptExample script Reading from a file ► reading line by line $line = ; ► reading all at = ;  Example scriptExample script Web Programming 10

Advanced I/O Command line arguments holds command line arguments e.g. prog1.pl arg1 holds (arg1, arg2)  Example scriptExample script Working with a directory ► Open a directory opendir (IND, $directory); ► Read the = readdir (IND); ► Close the directory closedir (IND);  Example scriptExample script Web Programming 11