Introduction to Perl Jarrad Battaglia.

Slides:



Advertisements
Similar presentations
1/12 Steven Leung Very Basic Perl Tricks A Few Ground Rules File I/O and Formatting Operators, Flow Control Statements Regular Expression Subroutines Hash.
Advertisements

● Perl reference
Perl Basics Chapters 1-6 of “Learning Perl” By Randal Schwartz, Tom Christiansen & Larry Wall; ISBN , 302 pages. Second Edition, July 1997.
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.
for($i=0; $i/)
Lecture 2 BNFO 135 Usman Roshan. Perl variables Scalar –Number –String Examples –$myname = “Roshan”; –$year = 2006;
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Introduction to Perl Part III By: Cedric Notredame Adapted from (BT McInnes)
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
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.
Sed, awk, & perl CS 2204 Class meeting 13 *Notes by Mir Farooq Ali and other members of the CS faculty at Virginia Tech. Copyright 2003.
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.
Introduction to Unix – CS 21
An Intro to Perl, Pt. 2 Hashes, Foreach Control, and the Split Function.
Introduction to Programming the WWW I CMSC Winter 2003.
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.
CPTG286K Programming - Perl Chapter 5 & 6: Hashes & Basic I/O.
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.
Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp
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.
Programming Perl in UNIX Course Number : CIT 370 Week 2 Prof. Daniel Chen.
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.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
By Joseph Patrick Brady. Overview  Hashes  foreach control statement  split function.
Lesson 3 Functions. Lesson 3 Functions are declared with function. For example, to calculate the cube of a number function function name (parameters)
Chapter 17 Arrays Perl to denote an array, for = (10, 20, 30, 50); Array subscripts are number from 0. Array elements require scalar.
Pseudocode Key Revision Points.
System Administration Introduction to Scripting, Perl Session 5 – Fri 23 Nov 2007 References: Perl man pages Albert Lingelbach, Jr.
Perl Programming Language Design and Implementation (4th Edition)
DBW - PHP DBW2017.
Arrays An array in PHP is an ordered map
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.
While Loops BIS1523 – Lecture 12.
Introduction to Python
Perl hashes, compound data structures, formatting output, and special variables.
Perl Variables: Array Web Programming.
Introduction to Python
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong.
Perl Variables: Hash Web Programming.
Control Structures: for & while Loops
Pemrosesan Teks Herika Hayurani Sept 19, 2006
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 Chapter 4 Arrays.
Chapter 5: Lists and Dictionaries
CS2011 Introduction to Programming I Arrays (I)
What's wrong with Easter jokes? They crack you up
Programming Control Structures with JavaScript Part 2
Loops and Arrays in JavaScript
CHAPTER 21 LOOPS 1.
PHP PART 2.
Java: Variables, Input and Arrays
awk- An Advanced Filter
Introduction to Python
Karan Thaker CS 265 Section 001
Presentation transcript:

Introduction to Perl Jarrad Battaglia

What I will be covering Foreach statements Hashes Splits

Hashes Hashes are very similar to arrays, but use strings instead of numbers for indexing Hashes use a key,value system Hash indices are called keys Say you create an array A(1..10) Hash(“one”,”1”,”two”,”2”) Hash{“one”} = “1” While Array [0] = 1

Reverse Hash Add new hash element Add multiple values to hash Format: $hash{“key”} = “value”; $hash{“one”} = “1”; Add multiple values to hash Format: %hash(“key1”, “value1”,”key2”, “value2”); %hash($key1 => $value1, $key2 => $value2) Reverse hash – so keys become values and values become keys %reverse_hash = reverse %hash;

Additional Hash Commands Delete one key-value from hash list delete $hash{key}; Delete all keys and values %hash = (); Check if key exists If(exists $hash{key}); Use variables in hash $hash{$key} = $value;

Hash to Array Hash to array Array to Hash %hash (“one”,”1”,”two”,”2”); @list = %hash List now has a size of 4 Array to Hash %hash = (); %hash = @list; Hash is now back to regular

Foreach statement Are used to iterate every value of an array or hash In an array the foreach statement will loop through every value of a list In a hash it will loop through the key, then go to its value, unless specified

Foreach examples Loop through hash with foreach Loop through a list foreach $hash (keys %hash) { print “keys\n”} Loop through a list foreach $list (@list) {print “$list\n” } foreach (@list) { print “$_\n” } Loop through numbers foreach (1..10) {print “$_\n”}

Foreach Example

Split Function The split function will split a scalar string into an array of strings For example @stringlist = split(/ /,"string into spaces"); foreach (@stringlist) { print “$_\n”; This would print “string”, “into”, “spaces” all on different lines

Split Examples Split two sentence into two Split input by spaces $string = “This is one. This is two” %splitstr = split(/\./,$string); Foreach(splitstr){print “$_\n”;} Split input by spaces $input = <STDIN>; foreach (split(“ “, $input)) { print “$_\n”;}

Hash Example