up
Perl Lecture Notes - September 14
- Why Perl and Java?
- "Not too much" vs "not too few" technologies
- Popularity; available libraries and code
- Radically different but both C-ish
- Open Source / Standards
- Perl strengths and weaknesses
- Sample Perl code:
- Getting started 1 - administration and background
- 3 trimester basic schedule for IPL
- Perl Books: what each is for; "Learning" pro's / con's; Camel book.
- The wiki and other class websites
- contacting us
- grading policies and submitting work ( via online gradebook; still coming )
- Getting started 2 - nuts and bolts of writing/running/debugging perl
- unix and ssh-ing in
- installing Perl and/or getting access to it: unix, mac, windows
- manuals, documention, resources
- editors: emacs, xemacs, vim, ...
- use "perl -w your_file" to see warnings
- use "perl -d your_file" to invoke the debugger (more later on this)
- use "perl -de1" for "interactive" attempts
- making it executable : #!/bin/perl and chmod +x filename
- organizing your assignments and work on bob/~you/
- Diving in with Perl data types : $, @, %, & and syntax assumptions
- syntactic definition with special symbols - like language word endings.
- Motivation: print " The answer is $foo "
- Data types:
- $foo = scalar (string, int, real, reference)
- @foo = array
- %foo = hash ( coming )
- &foo = subroutine (coming )
- Strings: quotes, interpretation, "here-is", . concatenation
- Int/Real (and String) auto-conversion, 1, 1.2e-3, others
- Boolean: "", (), 0, undef : false
- Array
- @foo = ( 1, "hello", 4, (2 , "six" ) ); # gives list
- $foo[1] # is "hello"
- @foo[0..3] # is (1, "hello", 4, 2)
- scalar vs array "context".
- many, many built-in functions: length, reverse, sort, ...
- function calls may omit () : print("hello") vs print "hello"
(so how does it know when to stop? Depends on what it tries to grab...)
- Some cases that may not do what you expect :
- $a = (10, 20, 30);
- @a = 3;
- @a = (10, 20, 30);
- ($a) = (10, 20, 30);
- $b = @a; # compare with first example...
- $a = 1, 2, 3
- print "hi", "there", "you";
- print length "hi, "there", "you";
- print (2+3)*5, "is the answer";
- if time allows (or read in Llama):
if, while, chomp, STDIN, print, qw, pop, push, shift,
sort, reverse, " $interpolation ", #comments, foreach, $_
- Assignment:
- Read chapters 1, 2, 3 in the Llama book.
- Install perl on your home machine and/or explore ways to
use it on bob.marlboro.edu and your linux box.
Try out vi. Try out emacs. Play around.
- Do Llama 1.1, 2.4, 3.3
- Are we having fun yet?