Presentation is loading. Please wait.

Presentation is loading. Please wait.

Organization of Programming Languages Meeting 37 April 18, 2016.

Similar presentations


Presentation on theme: "Organization of Programming Languages Meeting 37 April 18, 2016."— Presentation transcript:

1 Organization of Programming Languages Meeting 37 April 18, 2016

2 Planning Ahead Palindrome project due today – Submit Lisp functions in file attached to email Quiz 3 on Wednesday – Scripting languages – AWK – Regular expressions More scripting, different style

3 PERL Practical Extraction and Support Language A glue language under Unix Written by Larry Wall See www.perl.org

4 PERL Scripting language More powerful than AWK More flexible than shell scripts Syntax derived from C Large language Later versions contain classes Many irregularities in design Many alternatives for syntax Designed to minimize keystrokes while programming

5 PERL Beginning assumptions and notations Statements are terminated by ; (semicolon) Comments start with # and occupy the rest of the line. – NO two-line comments Parentheses around arguments to built-in functions are optional – length(x) and length x mean the same thing

6 PERL First line of program is an interpreter directive, written as a special type of comment, giving the full path to the Perl interpreter #!/usr/local/bin/perl -w

7 Example 1 #!/usr/local/bin/perl –w print(“Hello, world!\n”);

8 Example 1 #!/usr/local/bin/perl –w print(“Hello, world!\n”); Inserts new line character

9 PERL Scalars – Integer, real, string Identifier must start with $ – scalar matches something that looks like an S, namely $

10 PERL Arrays – Indexed by integers Identifier must start with @ – Array matches something that looks like A, namely @ – Indexed by strings Identifier must start with % – Hash is weird

11 Example 2 #!/usr/local/bin/perl –w print(“What is your name? ”); $name = ; chomp($name); print “Hello, $name!\n”;

12 Example 2 #!/usr/local/bin/perl –w print(“What is your name? ”); $name = ; chomp($name); print “Hello, $name!\n”; Critical space

13 Example 2 #!/usr/local/bin/perl –w print(“What is your name? ”); $name = ; #Reads one line chomp($name);#Cuts off EOL print “Hello, $name!\n”;

14 Example 2 #!/usr/local/bin/perl –w print(“What is your name? ”); $name = ; #Reads one line chomp($name);#Cuts off EOL print “Hello, $name!\n”;

15 PERL Control structures if-then-elsif-else foreach $element (%list) { … }

16 Example 3 #!/usr/local/bin/perl –w print “What is your name? ”; $name = ; chomp($name); if ($name eq “Nico”) {print “Hello, $name! Glad you’re here.\n”} elsif ($name eq “Daphne”) {print “Going outside, $name?\n”} else {print “Hello, $name.\n”};

17 PERL Dynamically typed – Type inferred from operations – Compare 2 < 10 (true) 2 lt 10 (false) 2 < “10” (true) “2” lt 10 (false) Numbers, strings, regular expressions Operators are not overloaded – For example, + only means add


Download ppt "Organization of Programming Languages Meeting 37 April 18, 2016."

Similar presentations


Ads by Google