Topic 1: Welcome CSE2395/CSE3395 Perl Programming.

Slides:



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

Chapter 25 Perl and CGI (Common Gateway Interface)
A Guide to Unix Using Linux Fourth Edition
The Linux Operating System Lecture 6: Perl for the Systems Administrator Tonga Institute of Higher Education.
Adv. UNIX:Perl/81 Advanced UNIX v Objectives of these slides: –introduce Perl (version ) –mostly based on Chapter 1, Learning Perl
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...
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Learning Web development. 3(+1) Tier architecture PHP script Remote services Web Server (Apache, IIS) Browser (IE, FireFox, Opera) Desktop (PC or MAC)
Introduction to Java Programming, 4E
Introduction to Perl Learning Objectives: 1. To introduce the features provided by Perl 2. To learn the basic Syntax & simple Input/Output control in Perl.
Scripting Languages. Originally, a script was a file containing a sequence of commands that needed to be executed Control structures were added to make.
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
Guide To UNIX Using Linux Third Edition
CSE S. Tanimoto Perl Introduction 1 Perl Practical Extraction and Report Language Shell-level scripting language: Glue that ties together programs.
Perl R and SQL for the very beginners Christoph Rau, Calvin Pan and Yehudit Hasin Dec 2011.
Systems Software Operating Systems.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class One Instructor:
 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.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 03.
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
Nael Alian Introduction to PHP
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
CS 105 Perl: Course Introduction Nathan Clement 13 May 2014.
Introduction to Java Programming with Forte Y. Daniel Liang.
LING/C SC/PSYC 438/538 Lecture 2 Sandiway Fong. Today’s Topics Did you read Chapter 1 of JM? – Short Homework 2 (submit by midnight Friday) Today is Perl.
Lecture 10A Perl: Programming Freedom Fundamentals of Engineering For Honors – H192 By Robert Mohr, Ted Pavlic, and Joe Ryan.
Systems Software Operating Systems. What is software? Software is the term that we use for all the programs and data that we use with a computer system.

Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to Perl Yupu Liang cbio at MSKCC
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.
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
CS4710 Why Progam?. Why learn to program? Utility of programming skills: understand tools modify tools create your own automate repetitive tasks automate.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
Introducing System Managers to Win32 Perl Programming Tim Christian College of Arts and Sciences Computing Support Services.
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
1 Introduction to Scripting Languages (with Perl).
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
An Overview of Perl A language for Systems and Network Administration and Management: An overview of the language.
Perl COEN 351  Thomas Schwarz, S.J Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.
Topic 2: Working with scalars CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 2, pages 19-38, Programming Perl 3rd edition chapter.
(the language for getting your job done) Internet Programming Diana Hingst.
CSE S. Tanimoto Perl-Intro - 1 Perl Practical Extraction and Report Language Shell-level scripting language: Glue that ties together programs written.
Topic 3: Lists and arrays CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 3, pages 40-55, 86-91, Programming Perl 3rd edition.
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.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
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.
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.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Perl A language for Systems and Network Administration and Management.
Introduction to Perl: Practical extraction and report language
CS 330 Class 7 Comments on Exam Programming plan for today:
Department of Computer Engineering
PERL.
PERL.
Perl Programming Language Design and Implementation (4th Edition)
Programming Basics Web Programming.
Perl Practical Extraction and Report Language
Perl Practical Extraction and Report Language
Introduction to Perl Learning Objectives:
Presentation transcript:

Topic 1: Welcome CSE2395/CSE3395 Perl Programming

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 2 In this topic  Introduction to Perl  Introduction to this unit  Outline of topics ► what’s examinable  Simple Perl programs ► and how to run them  Introduction to Perl  Introduction to this unit  Outline of topics ► what’s examinable  Simple Perl programs ► and how to run them

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 3 What is Perl?  A general-purpose programming language ► The “Swiss-army chainsaw” of programming  A scripting language ► partly compiled, partly interpreted  A rapid prototyping language ► “Easy things should be easy, and hard things should be possible” ► Very flexible typing ► Rich programming environment  A general-purpose programming language ► The “Swiss-army chainsaw” of programming  A scripting language ► partly compiled, partly interpreted  A rapid prototyping language ► “Easy things should be easy, and hard things should be possible” ► Very flexible typing ► Rich programming environment

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 4 What is Perl?  From man page ► Perl is a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. ► It's also a good language for many system management tasks. ► The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).  From man page ► Perl is a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. ► It's also a good language for many system management tasks. ► The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 5 Strengths of Perl  Simple ► simple problems have simple solutions  Practical ► common tasks are supported by language  Portable ► Unix, Windows, Mac OS, BeOS, AmigaDOS,...  Extensible ► vast library support ► can link to other programming languages  Robust ► difficult to crash ► good security support  Free ► as in speech and beer  Simple ► simple problems have simple solutions  Practical ► common tasks are supported by language  Portable ► Unix, Windows, Mac OS, BeOS, AmigaDOS,...  Extensible ► vast library support ► can link to other programming languages  Robust ► difficult to crash ► good security support  Free ► as in speech and beer

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 6 Why use Perl?  Programs that are ► too small to bother with C ► too complex for shell programming ► write once, throw away (on command line) ► in continuous development ► for wide distribution ► in an area where Perl is well supported –e.g., Perl can be built in to Apache web server  Programs that are ► too small to bother with C ► too complex for shell programming ► write once, throw away (on command line) ► in continuous development ► for wide distribution ► in an area where Perl is well supported –e.g., Perl can be built in to Apache web server

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 7 Why not use Perl?  Consider something other than Perl if ► you crave clarity of code –Perl sometimes considered difficult to read –“Obfuscated Perl” and “Perl Poetry” contests –try Java or Python instead ► speed is paramount –Perl is fast, but compiled C is about 20% faster ► it’s a large-scale project –Perl scales well, but not as well as C++ ► you have to –Perl may not be loved by your boss –look for a better job  Consider something other than Perl if ► you crave clarity of code –Perl sometimes considered difficult to read –“Obfuscated Perl” and “Perl Poetry” contests –try Java or Python instead ► speed is paramount –Perl is fast, but compiled C is about 20% faster ► it’s a large-scale project –Perl scales well, but not as well as C++ ► you have to –Perl may not be loved by your boss –look for a better job

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 8 Getting Perl  /usr/bin/perl ► most Unix systems already have it  CPAN ► Comprehensive Perl Archive Network ► ► source code  Active State ► ► precompiled Windows version with installer wizard  /usr/bin/perl ► most Unix systems already have it  CPAN ► Comprehensive Perl Archive Network ► ► source code  Active State ► ► precompiled Windows version with installer wizard Llama3 pages 8-9; Camel3 page xxiii

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 9 Getting help  From the lecturer ► David Abramson ► ► phone ► room 193(75)  At the tutorial ► more information soon  From unit’s courseware area ► ► these lecture notes  From unit newsgroup ► monash.csse.cse2395  From each other ► see courseware page for cheating policy  From the lecturer ► David Abramson ► ► phone ► room 193(75)  At the tutorial ► more information soon  From unit’s courseware area ► ► these lecture notes  From unit newsgroup ► monash.csse.cse2395  From each other ► see courseware page for cheating policy

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 10 Getting help  From comp.lang.perl.misc newsgroup ► worldwide home of Perl on Usenet  From Unix manual pages (“manpages”) ► man perl ► perldoc  From CPAN ► ► Online manual pages and FAQs  From comp.lang.perl.misc newsgroup ► worldwide home of Perl on Usenet  From Unix manual pages (“manpages”) ► man perl ► perldoc  From CPAN ► ► Online manual pages and FAQs Llama3 pages 9-12; Camel3 pages xxv-xxviii; perldoc manpage

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 11 Texts  Learning Perl (“Llama book”) ► Randal Schwartz, Tom Phoenix ► O’Reilly & Associates, third edition 2001 ► second edition still relevant ► recommended for those who want a tutorial  Programming Perl (“Camel book”) ► Larry Wall, Tom Christiansen, Jon Orwant ► O’Reilly & Associates, third edition 2000 ► second edition still relevant ► recommended for those strong in programming  Learning Perl (“Llama book”) ► Randal Schwartz, Tom Phoenix ► O’Reilly & Associates, third edition 2001 ► second edition still relevant ► recommended for those who want a tutorial  Programming Perl (“Camel book”) ► Larry Wall, Tom Christiansen, Jon Orwant ► O’Reilly & Associates, third edition 2000 ► second edition still relevant ► recommended for those strong in programming This icon indicates a book/manpage reference

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 12 Unit overview  Thirteen one-hour lectures ► covering about a dozen topics  Assessment ► two assignments (10% each) ► final exam (80%) –Conventional 3 hour exam –Previous exams were practical ones  Thirteen one-hour lectures ► covering about a dozen topics  Assessment ► two assignments (10% each) ► final exam (80%) –Conventional 3 hour exam –Previous exams were practical ones

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 13 Topics covered  Scalar values and variables ► numbers and strings  List values and variables ► arrays  Control structures ► if, while, for, etc.  Subroutines ► functions  Perl debugger  Scalar values and variables ► numbers and strings  List values and variables ► arrays  Control structures ► if, while, for, etc.  Subroutines ► functions  Perl debugger

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 14 Topics covered  Hash table (“hashes”) ► aka associative arrays  File I/O ► manipulating files and directories  Regular expressions ► pattern matching  System administration ► processing system files  Modules and libraries ► code re-use  Hash table (“hashes”) ► aka associative arrays  File I/O ► manipulating files and directories  Regular expressions ► pattern matching  System administration ► processing system files  Modules and libraries ► code re-use

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 15 Topics covered  Databases ► persistent data structures  CGI ► Common Gateway Interface ► dynamic web pages  References ► self-referential data structures  Databases ► persistent data structures  CGI ► Common Gateway Interface ► dynamic web pages  References ► self-referential data structures

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 16 Topics covered  Object-oriented programming ► green-background slides examinable only for students doing CSE3395  Object-oriented programming ► green-background slides examinable only for students doing CSE3395

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 17 Schedule

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 18 Perl conventions  Perl is like C and Java... ► blocks of code group with { braces } –but braces always required with if and while ► statements end with semicolon ; ► white space usually optional ► all words are case sensitive –STDIN and stdin are different names  Perl is like C and Java... ► blocks of code group with { braces } –but braces always required with if and while ► statements end with semicolon ; ► white space usually optional ► all words are case sensitive –STDIN and stdin are different names

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 19 Perl conventions  Perl is different... ► comments start with # character –until end of line –like shell programming ► parentheses on function call are optional –sometimes needed to disambiguate ► no need to predeclare variables –undefined variables evaluate to reasonable “empty” value ► variables start with special symbol –$ or %, depending on type ► no main function/method –code is executed as it is met  Perl is different... ► comments start with # character –until end of line –like shell programming ► parentheses on function call are optional –sometimes needed to disambiguate ► no need to predeclare variables –undefined variables evaluate to reasonable “empty” value ► variables start with special symbol –$ or %, depending on type ► no main function/method –code is executed as it is met

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 20 A sample program # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n"; # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n";

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 21 A sample program # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n"; # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n"; Comments

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 22 A sample program # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n"; # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n"; Keyword

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 23 A sample program # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n"; # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n"; Functions

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 24 A sample program # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n"; # Read in lines until EOF. while (defined ($input = )) { chomp $input; $input; } # Get a random number of the right size. srand; $pick = # print line indexed by $pick print $lines[$pick], "\n"; Variables

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 25 Running a Perl program % perl greeting Hello, world! print "Hello, World!\n"; greeting Llama3 pages 12-14

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 26 Running a Perl program % chmod +x greeting %./greeting Hello, world! #!/usr/bin/perl -w print "Hello, World!\n"; greeting Llama3 pages 13-14; Camel3 pages In Unix, can make a script executable with chmod to run it just by typing its name

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 27 Running a Perl program % chmod +x greeting %./greeting Hello, world! #!/usr/bin/perl -w print "Hello, World!\n"; greeting Llama3 pages Magic code ( #! ) on first line of file Interpreter ( /usr/bin/perl -w ) ( -w turns on warnings) Make script executable Automatically translated by OS into /usr/bin/perl -w./greeting

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 28 Timeout # You can already read and write some Perl. print "Enter a number: "; $number = ; # Read into $number. for ($i = 2; $i <= sqrt $number; $i++) { if ($number % $i == 0) { print "$number is composite\n"; exit 0; } print "$number is prime\n"; # You can already read and write some Perl. print "Enter a number: "; $number = ; # Read into $number. for ($i = 2; $i <= sqrt $number; $i++) { if ($number % $i == 0) { print "$number is composite\n"; exit 0; } print "$number is prime\n";

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 29 Covered in this topic  Introduction to Perl  Introduction to the unit  Outline of topics  Simple Perl programs ► and how to run them  Introduction to Perl  Introduction to the unit  Outline of topics  Simple Perl programs ► and how to run them

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 30 Going further  CPAN ► where to begin any Perl quest ►  Command-line options ► e.g., -w to turn on warnings ► writing quick-and-dirty one-line programs ► Camel3 pages ► perlrun manpage  CPAN ► where to begin any Perl quest ►  Command-line options ► e.g., -w to turn on warnings ► writing quick-and-dirty one-line programs ► Camel3 pages ► perlrun manpage

Original Slides by Debbie Pickett, Modified by David Abramson, 2006, Copyright Monash University 31 Next topic  Scalar values and operations ► strings and numbers  Scalar variables  Scalar operations  if and unless  while and until  Scalar values and operations ► strings and numbers  Scalar variables  Scalar operations  if and unless  while and until Llama3 chapter 2 Camel3 pages 6-8, perldata manpage