Lecture 10A Perl: Programming Freedom Fundamentals of Engineering For Honors – H192 By Robert Mohr, Ted Pavlic, and Joe Ryan.

Slides:



Advertisements
Similar presentations
A Guide to Unix Using Linux Fourth Edition
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Fundamentals of Python: From First Programs Through Data Structures Chapter 2 Software Development, Data Types, and Expressions.
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.
Lecture 10A Perl: Programming Freedom Fundamentals of Engineering For Honors – H192 By Ted Pavlic and Joe Ryan.
Introduction to Perl Bioinformatics. What is Perl? Practical Extraction and Report Language A scripting language Components an interpreter scripts: text.
CSET4100 – Fall 2009 Perl Introduction Scalar Data, Operators & Control Blocks Acknowledgements: Slides adapted from NYU Computer Science course on UNIX.
CSE S. Tanimoto Perl Introduction 1 Perl Practical Extraction and Report Language Perl: Developed by Larry Wall in the late 1980s. Builds on...
Chapter 10.
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.
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
JavaScript, Third Edition
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
CSE S. Tanimoto Perl Introduction 1 Perl Practical Extraction and Report Language Shell-level scripting language: Glue that ties together programs.
C OMPUTER P ROGRAMMING 1 Introduction to the C Language.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
CSC 142 A 1 CSC 142 Introduction to Java [Reading: chapter 0]
Practical Extraction & Report Language PERL Joseph Beltran.
Introduction to Python
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
Fundamentals of Python: First Programs
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to Perl Yupu Liang cbio at MSKCC
Geog Basic Skills in Scientific Programming Syllabus, Introduction, Fundamentals of IDL Syntax.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
Introduction to Unix – CS 21
Variables, Expressions and Statements
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
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
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
CSE S. Tanimoto Perl-Intro - 1 Perl Practical Extraction and Report Language Shell-level scripting language: Glue that ties together programs written.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Chapter 9: Completing the Basics. In this chapter, you will learn about: – Exception handling – Exceptions and file checking – The string class – Character.
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.
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
PZ02CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02CX - Perl Programming Language Design and Implementation.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
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.
Programming Languages Meeting 12 November 18/19, 2014.
Linux Administration Working with the BASH Shell.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
Introduction to Perl: Practical extraction and report language
Topics Designing a Program Input, Processing, and Output
Perl Programming Language Design and Implementation (4th Edition)
Introduction to C++ Programming
Perl Practical Extraction and Report Language
Pemrosesan Teks Herika Hayurani Sept 19, 2006
“If you can’t write it down in English, you can’t code it.”
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Perl Practical Extraction and Report Language
INTRODUCTION to PERL PART 1.
PHP –Regular Expressions
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Lecture 10A Perl: Programming Freedom Fundamentals of Engineering For Honors – H192 By Robert Mohr, Ted Pavlic, and Joe Ryan

Lecture 10A Perl: Programming Freedom What is Perl? Why should I use Perl? What does Perl look like? Show me some examples. Conclusion

Lecture 10A Practical Extraction and Report Language Debuted on December 18, 1987 (Ted was 6) Invented by Larry Wall – Linguist and Computer Scientist Programming Perl: 3 rd Edition – The essential book on Perl – (O’Reilly) CS&E – 1 Credit Hour Spring S/U Course on Perl at OSU

Lecture 10A Practical? Report? This doesn’t have to do with labs, does it? Originally meant to be a glue language – Many applications, many platforms, many files, much power... With no way to communicate Need for a general purpose tool with a strong ability for text processing and reporting Text Processing? World Wide Web? How could those two possibly relate?! The embodiment of computational synergy?

Lecture 10A Perl vs. C: Major Distinctions Perl is interpreted, C is compiled. Negatives: – Perl requires additional overhead (CPU time, memory, etc.) – Perl code is slower than C, all other things being equal Positives: – Perl is easier to extend & upgrade without recompiling – Perl is not platform-specific, but C is – Perl implements powerful features without needing new architecture – Perl is constantly growing; powerful modules can be easily added – Perl has major security features as part of the language – Perl is great for rapid prototyping

Lecture 10A Perl vs. C: Syntax and Operators Borrows syntax from C, awk, BASIC, Python, Pascal, English, Greek – Extremely familiar, comfortable, and unconventional Flexible operators and constructs – do, for, while, ==, =,, ++, --, +, -, *, /, !, &&, || – foreach, unless, until, =~, eq, ne, and, or, not (and more…) Loosely-typed variables and automatic conversions Built-in text string comparison, parsing, pattern-matching Simple I/O library Hundreds of pre-written modules extend Perl for many tasks – (CPAN: Easy object-oriented programming

Lecture 10A Perl Data Types: Scalars ($) Scalars store numeric and string data (and more!) Syntax: $scalar_name Automatic conversion between numeric and text data types when appropriate $x = 5; $y = -6.7; $z = “foo”; $a = $x + $y;# $a == -1.7 $b = $z. $x;# $b eq “foo5” $t = “hello” x 5;# $t eq “hellohellohellohellohello” $g = $x ** 2;# exponentiation – $g == 25

Lecture 10A Scalar Example With Some Twists # Declare and initialize some scalars to play with $w = 1; $x = 2; $y = “2”; $z = “4.5”; $s = “text”; If (1 == $w) { print “w = 1\t”; }# Compare scalar & constant print “x = y = $x\t” if ($x == $y); # Compare two scalars # Notice placement of if while($z > $y) { $z--; }# while / decrement scalar print( “z = $z\n” );# Print scalar value print “Of course $z isn’t the same as $s!\n” if ($z ne $s); # String “not-equal” compare Output w = 1x = y = 2z = 1.5 Of course 1.5 isn’t the same as text!

Lecture 10A Perl Regular Expressions allow for matching strings against patterns special characters –. matches any character – * matches 0 or more of the preceding character – ? matches 0 or 1 of the preceding character – + matches 1 or more of the preceding character escape sequences – \d matches any (d)igit – \s matches any white(s)pace (tab “\t”, space “ ”, newline “\n”) – \w matches any alphanumeric “(w)ord” character capturing – parentheses in the pattern (e.g., m/(\d)\d/) cause the portion of the string in the parentheses to be captured into a temporary variable

Lecture 10A example: $str =~ m/a*b?\+\d/ matches – 0 or more “a”s (e.g., “”, “a”, “aa”, etc.) followed by – 0 or 1 “b”s (e.g., “”, “b”) followed by – a literal “+” (the backslash escapes the “+”) followed by – 1 digit 0-9 (\d – (d)igit) example: “12345” =~ m/\d(\d)\d(\d)\d/ – sets $1 to “2” (first set of parentheses) – sets $2 to “4” (second set of parentheses) example: “12345” =~ m/(\d(\d)\d)\d\d/ – sets $1 to “123” (first set of parentheses) – sets $2 to “2” (second set of parentheses) Perl Regular Expression Usage

Lecture 10A Perl Regular Expression Example # Declare and initialize some arrays of famous people’s names for my $prof (“Dr. Demel”, “Dr. Freuler”, “Mr. Clingan”) { if ( $prof =~ m/Dr\. (.*)/) { print $1,” has a PhD\n”; }

Lecture 10A Perl I/O Print to standard output (screen) – print “text”; print $scalar; print STDOUT “text”; Read from standard input (keyboard) – $line = ; chomp $line; The angle operator (<>) (used very frequently!) – chomp( $line = <> );

Lecture 10A Perl File I/O Open a file – open(IN, “filename”);# Open for reading open(OUT, “>filename”);# Open for writing open(OUT, “>>filename”);# Open for appending Input from file referenced by the handle “IN” – $line = ; Print to the file referenced by the handle “OUT” – print OUT “text”; Close a file – close IN; close OUT;

Lecture 10A Perl File I/O Example print “Enter file to read: “;# Ask user for a filename $filename = ;# Retrieve entire line chomp $filename;# Get rid of ‘\n’ if there open(IN, $filename);# Open the files (notice file open(OUT, “>example.out”);# descriptors IN and OUT) while($line = ) {# Print out to screen/file print $line; print OUT $line; } close OUT;# Close file handles close IN;

Lecture 10A Learn more than one language? That’s dumb even for a geek. Perl motto: TMTOWTDI There’s More Than One Way To Do It

Lecture 10A Please End; Really, Leave! Any questions?