An Intro to Perl, Pt. 2 Hashes, Foreach Control, and the Split Function.

Slides:



Advertisements
Similar presentations
References and Data Structures. References Just as in C, you can create a variable that is a reference (or pointer) to another variable. That is, it contains.
Advertisements

1 Arrays in PHP PHP Functions. 2 Array Definition An array is a complex variable that enables you to store multiple values in a single variable; It comes.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong. Administrivia Homework 1 graded – you should have gotten an from me.
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 Basics Chapters 1-6 of “Learning Perl” By Randal Schwartz, Tom Christiansen & Larry Wall; ISBN , 302 pages. Second Edition, July 1997.
COS 381 Day 19. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
Scripting Languages Chapter 5 Hashes. Hash Data structure, not unlike an array – it will hold any number of values It indexes values by name – not by.
Hashes a “hash” is another fundamental data structure, like scalars and arrays. Hashes are sometimes called “associative arrays”. Basically, a hash associates.
A String T h e Q u i c k B r o w n F o x 0 str char str[100]; strcpy(str, “The Quick Brown Fox”);
Lecture 2 BNFO 135 Usman Roshan. Perl variables Scalar –Number –String Examples –$myname = “Roshan”; –$year = 2006;
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 8: Perl Basics Fundamentals of Web Programming.
Introduction to Perl Part III By: Cedric Notredame Adapted from (BT McInnes)
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.
The Ruby Programming Language
The foreach LooptMyn1 The foreach Loop The foreach loop gives an easy way to iterate over arrays. foreach works only on arrays, and will issue an error.
1 An Introduction to Perl Part 2 CSC8304 – Computing Environments for Bioinformatics - Lecture 8.
Computer Programming for Biologists Class 7 Nov 27 th, 2014 Karsten Hokamp
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
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.
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 .
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Introduction To Perl Susan Lukose. Introduction to Perl Practical Extraction and Report Language Easy to learn and use.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 5 Server Side Scripting Perl.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
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.
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.
LING/C SC/PSYC 438/538 Lecture 3 8/30 Sandiway Fong.
Array & Foreach อาร์เรย์และคำสั่งวนลูป. Content 1. Definition and Usage 2. Syntax 3. print_r() Statement 4. For and Foreach 5. Array Functions.
Prof. Alfred J Bird, Ph.D., NBCT -bird.wikispaces.umb.edu/ Office – McCormick 3rd floor.
Arrays. Indexed Arrays Use numbers as keys: $grades = array(); $grades[0] = ' A ' ; $grades[1] = ' A- ' ; $grades[2] = ' B+ ' ; Or with one statement:
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.
Introduction to Perl Part III By: Bridget Thomson McInnes 6 Feburary 2004.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong. Administrivia Homework 2 graded.
5 1 Data Files CGI/Perl Programming By Diane Zak.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
CS 330 Class 9 Programming plan for today: More of how data gets into a script Via environment variables Via the url From a form By editing the url directly.
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.
CPTG286K Programming - Perl Chapter 4: Control Structures.
CS 105 Perl: Basic I/O, Context, Strings, Lists Nathan Clement January 22, 2014.
Digital Text and Data Processing Tokenisation. Today’s class □ Tokenisation and creation of frequency lists □ Keyword in context lists □ Moretti and distant.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
CPTG286K Programming - Perl Chapter 5 & 6: Hashes & Basic I/O.
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.
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.
Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
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];
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
CSC 4630 Meeting 17 March 21, Exam/Quiz Schedule Due to ice, travel, research and other commitments that we all have: –Quiz 2, scheduled for Monday.
2000 Copyrights, Danielle S. Lahmani Foreach example = ( 3, 5, 7, 9) foreach $one ) { $one*=3; } is now (9,15,21,27)
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.
Perl Ed Finegan. Overview of Pearl Perl is a high-level programming language written by Larry Wall. It derives from the C programming language and to.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
1 CGI (Common Gateway Interface) CmpE 587 Emir Bayraktar Onur Bük.
By Joseph Patrick Brady. Overview  Hashes  foreach control statement  split function.
Chapter 17 Arrays Perl to denote an array, for = (10, 20, 30, 50); Array subscripts are number from 0. Array elements require scalar.
Perl Variables: Array Web Programming.
Introduction to Perl Jarrad Battaglia.
Perl Variables: Hash Web Programming.
Pemrosesan Teks Herika Hayurani Sept 19, 2006
PERL: part II hashes, foreach control statements, and the split function By: Kevin Walton.
Presentation transcript:

An Intro to Perl, Pt. 2 Hashes, Foreach Control, and the Split Function

Hashes (Associative Arrays) Arrays with string indices Each index is called a key Different braces than arrays ({} not []) Use the % sigil to symbolize a hash

Example Hashes $numbers{“one”}=”1”; Assigns 1 to key “one” $numbers{“two”}=”2”; (accessed as a scalar) $numbers{“three”}=”3”; %numbers=(“one”,”1”,”two”,”2”,”three”,”3”); Creates hash with indices one, two, three and values of 1, 2, and 3

Hash Control while(($key, $value) = each %numbers){ print "$key $value\n”;} Prints out individual Key-value pairs for the hash

Foreach Control Statement For loop designed for processing arrays, hashes, and “is”, “an”, “array”); foreach $word print = ('Larry', 'Curly', 'Moe'); foreach { print $_. “\n”;}

The Split Function Splits a string using a specific " ", $string; If $string = “The quick brown (“The”, “quick”, “brown”, “fox”) Default delimiter is a space “ “ $info = "Caine:Michael:Actor:14, Leafy = split(/:/, $info);