Perl Basics Chapters 1-6 of “Learning Perl” By Randal Schwartz, Tom Christiansen & Larry Wall; ISBN 1-56592-284-0, 302 pages. Second Edition, July 1997.

Slides:



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

Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
Bioinformatics is … - the use of computers and information technology to assist biological studies - a multi-dimensional and multi-lingual discipline Chapters.
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
CSET4100 – Fall 2009 Perl Introduction Scalar Data, Operators & Control Blocks Acknowledgements: Slides adapted from NYU Computer Science course on UNIX.
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.
Scalar Variables Start the file with: #! /usr/bin/perl –w No spaces or newlines before the the #! “#!” is sometimes called a “shebang”. It is a signal.
Practical Extraction & Report Language Picture taken from
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
JavaScript, Third Edition
Shell Scripting Awk (part1) Awk Programming Language standard unix language that is geared for text processing and creating formatted reports but it.
Practical Extraction & Report Language PERL Joseph Beltran.
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
A Guide to Unix Using Linux Fourth Edition
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
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.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Awk Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
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.
Introduction to Perl Yupu Liang cbio at MSKCC
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.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
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.
Revision Lecture Mauro Jaskelioff. AWK Program Structure AWK programs consists of patterns and procedures Pattern_1 { Procedure_1} Pattern_2 { Procedure_2}
Introduction to Unix – CS 21
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
LIN Unix Lecture 7 Hana Filip. LIN Text Processing Command Line Utility Programs (cont.) sed LAST WEEK wc sort tr uniq awk TODAY join paste.
Introduction to PHP.
Introduction to Perl William G. Dishman CUR/516 November 5, 2014.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
CPTG286K Programming - Perl Chapter 4: Control Structures.
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.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
Programming Perl in UNIX Course Number : CIT 370 Week 3 Prof. Daniel Chen.
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
Awk- An Advanced Filter by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
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.
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.
PZ02CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02CX - Perl Programming Language Design and Implementation.
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: Practical Extraction & Reporting Language RL Schwartz, Learning Perl, RL Schwartz & L Wall, Programming Perl, O’Reilly & Associates.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Organization of Programming Languages Meeting 37 April 18, 2016.
PHP using MySQL Database for Web Development (part II)
Perl Programming Language Design and Implementation (4th Edition)
Variables, Expressions, and IO
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
PHP Introduction.
Introduction to Python
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
T. Jumana Abu Shmais – AOU - Riyadh
Chapter Four UNIX File Processing.
Presentation transcript:

Perl Basics Chapters 1-6 of “Learning Perl” By Randal Schwartz, Tom Christiansen & Larry Wall; ISBN , 302 pages. Second Edition, July 1997.

What is Perl? Perl is short for "Practical Extraction and Report Language," or "Pathologically Eclectic Rubbish Lister.” Both are endorsed by Larry Wall, Perl's creator and chief architect, implementor, and maintainer. He created Perl when he was trying to produce some reports from a Usenet-news-like hierarchy of files for a bug-reporting system, and awk ran out of steam.

Where does Perl fit? Perl is a high level language that fits between C and a shell interpreter. Since it is an interpreted language, it can be used between systems. It is available on UNIX systems, VMS, Windows 9x/NT, and Macintosh. Go to

Things to remember about Perl There’s usually more than two ways to do things in Perl. It’s easy to write code that may become unable to be read seconds afterwards. If you learn how to use “regular expressions”, you can do great things in one or two lines.

Walking through a Perl program First line usually starts with –#!/usr/bin/env perl This is a UNIX notation to indicate that it is a Perl program. Usually name perl programs with.pl

Small Perl Script while (<>) { –print; }

Defined/Undefined variables Variables do not have to be defined before you use them. They just don’t exist until you give them a value. “undef” can delete a variable from the running script.

Basic Variables in Perl $var = “Text”; $var = %hash=qw(a b c d); $hash{“a”}=“b”; $array[0]=1; $a= ; String variable Numeric variable Array of values Hash table Hash entry Array entry Read from keyboard

Standard arithmetic operators + - * / % Addition Subtraction Multiplication Division Remainder (mod) Increment Decrement

String operators $a = “a”.$b; $line=“-”x80; chop($a); chomp($a) Concatenation Repetition Drop last letter Drop last white space

Logical Operators

Controlling Perl Statement Blocks (curly braces {}) if/unless while/until for foreach

Statement Blocks A sequence of statements enclosed in curly braces. { –Stuff; }

Conditional: if/unless if, if/else, if/elsif/else –“if something is true, do it” –if ($x > 50) {print “too much }; –print “Too much” if ($x > 50); unless –“do it if something is false” –print “Too much” unless ($x < 50);

Iteration with while/until while –“while something is true, do block” until –“until something is true, do block” do/while, do/until –Check after doing the block

The “for” statement Iterate over a range of values Format: –for (initial; test; increment/decrement) –for { print “$a[$i]\n”; }

The “foreach” command Iterate over a list of elements Format: –foreach $value { print “$value\n”; }

“showdisks.pl” A script to compute how much disk space is on sgenab. Uses hash tables to store info Uses the ability to look through the output of system commands.

Get the names of the disks open(DEVICES,”show devices |”); while( ) { –if (/DK/) { $name[$nd++]=$_; } –}; close(DEVICES);

For each disk... foreach $disk { –($d,$stuff)=split(/ /,$disk,2); –open(DISKINFO,”show dev/full $d |”); –while( ) { $total{$d}=substr($_,12,20) if (/Total blocks/); $free{$d}=substr($_,12,20) if (/Free blocks/); } –close(DISKINFO); }

Print out results foreach $disk (sort (keys $free)) { –print “$disk\t$free{$disk}\t$total{$disk}\n”; –}

Basic I/O Perl can change the way it reads in from a file. $/ (Input record separator) $\ (Output record separator) $_ (Current line)

Printing stuff out in Perl Standard print –print “Hello World, $name.\n”; printf –printf (“Hello World, %s.\n”,$name); Formatted printing –Later... “\n” newline, “\t” tab