CS 105 Perl: Course Introduction
description
Transcript of CS 105 Perl: Course Introduction
CS 105 Perl:Course Introduction
Nathan Clement
13 May 2014
Agenda
• Course overview• Review syllabus• Informal survey• Next class: paper survey• Perl introduction
Perl origins
Larry Wall• Graduate study in linguistics• System administrator at NASA• Perl 1.0 in 1987
Perl 1.000NAMEperl | Practical Extraction and Report Language
SYNOPSIS perl [options] filename args
DESCRIPTION Perl is a interpreted language optimized for scanning arbi- trary 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, effi- cient, complete) rather than beautiful (tiny, elegant, minimal). It combines (in the author's opinion, anyway) some of the best features of C, sed, awk, and sh, so people familiar with those languages should have little difficulty with it. (Language historians will also note some vestiges of csh, Pascal, and even BASIC|PLUS.) Expression syntax corresponds quite closely to C expression syntax. If you have a problem that would ordinarily use sed or awk or sh, but it exceeds their capabilities or must run a little fas- ter, and you don't want to write the silly thing in C, then perl may be for you. There are also translators to turn your sed and awk scripts into perl scripts. OK, enough hype.
Perl over time
Path to Maturity• Perl 1.000 – December 18, 1987• Perl 2.000 – June 5, 1988• Perl 3.000 – October 18, 1989• Perl 4.000 – March 21, 1991• Perl 5.000 – October 18, 1994– “Complete rewrite”
• Perl 6.000 - ???– Project announced on July 19, 2000– “eventually evolved into a separate language”
Perl over time
Path to Maturity• Perl 1.000 – December 18, 1987• Perl 2.000 – June 5, 1988• Perl 3.000 – October 18, 1989• Perl 4.000 – March 21, 1991• Perl 5.000 – October 18, 1994– “Complete rewrite”– “Perl” means Perl5
Getting the name right
• Perl– Not PERL– The language is Perl– The interpreter is perl– Originally named Pearl– Some “backronyms” are in common use• Practical Extraction and Report Language• Pathologically Eclectic Rubbish Lister
More Perl culture
• There’s more than one way to do it(TMTOWTDI)– Golfing– Conciseness– Terseness– Obfuscation
Do What I Mean
Do What I Mean (DWIM)The evolution of DWIM:
DWIM → DWIMmy → dwimmy“perl dwimmy” on Google:• “So non-dwimmy open variants are a good idea to keep
around”• “Non-dwimmy hyperoperator”• “I don’t think this is DWIMMY at all.”• “that seems to be pretty dwimmy”
Programming Taxonomy:Where Perl Fits In
Perl…• is interpreted
– Compiled at runtime into bytecode– Bytecode is interpreted
• is dynamically typed– Variables don’t have types– Values have types
• has automatic memory management– Memory is not allocated by the programmer– No malloc/free, new/delete analogue
These features are typical of “scripting languages”
Programming Taxonomy:Perl’s Relatives
Just a few similar languages:• Python• PHP• Ruby
So Why Perl?
Perl PythonPHP
What is Perl good for?
• Text processing• Data manipulation (“munging”)• Quick development of tools• One-offs• System integration• “Glue” code• Databases, Web, etc.• “Real” systems
What is good about Perl?
• Very quick development– Once you learn it
• Easy things are easy, and typically short• Great documentation• Lots of books• Installed out of the box on many Unix platforms– or easily available as a package
• Typically comes “batteries included”– Especially since Perl 5.8 (2002)
• Huge collection of free modules (CPAN)
Your first Perl program
• Create a file– Open your editor– Save an empty file
• In another terminal, type perl that-file– This is one way to run your program
Your second Perl program
Type the following:print "Some boring text\n";
Save your file and run it.
Running Your Program Directly (1)
We don’t want to typeperl your-program
We’d rather type./your-program
Running Your Program Directly (2)
At the top of your program, type the following:#!/usr/bin/perl
This tells the program loader how to run your program.
From a terminal (outside your editor), typechmod +x your-program
This marks the file as executable so Unix will allow it to execute.
Very first line
“Hash-bang” line
Homework
Write your own Hello, World program that I can run like ./foo.
I don’t care what you print out, as long as it prints something.
This will require:• getting a Unix account• learning the rudimentary features of an editor• writing one correct Perl statement• learning how to use turnin
Homework Due Date
• Assignment 1 is due Wednesday, January 22,but I recommend completing it ASAP.