Presentation is loading. Please wait.

Presentation is loading. Please wait.

Perl COEN 351  Thomas Schwarz, S.J. 2006. Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.

Similar presentations


Presentation on theme: "Perl COEN 351  Thomas Schwarz, S.J. 2006. Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles."— Presentation transcript:

1 Perl COEN 351  Thomas Schwarz, S.J. 2006

2 Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles “Easy things should be easy.” “Hard things should be possible.” “Many ways to do the same thing.” Desired similarity to natural languages: Context important.

3 Perl Due to its popularity, there are outstanding resources on the web. www.perl.com www.perl.org

4 Installing and Running Perl COEN 351  Thomas Schwarz, S.J. 2006

5 Perl Perl is quasi-native to Unix systems. Activestate (www.activestate.com) distributes free windows version.www.activestate.com After installation, add Perl bin directory to your path. Associate.pl with Perl.exe in Explorer Test perl: “perl –v” in command prompt.

6 Perl Fundamentals COEN 351  Thomas Schwarz, S.J. 2006

7 Perl Simple “hello world” application.

8 Perl: Scalar Variables Variables: Untyped, but characterized by first character: Scalar: Numbers or strings. Start out with $: $number, $string, … All numbers have internally the same format. String literals can be defined with single or double quotes. There are different rules about special symbols. Number literals have to follow special formatting for non- decimal bases: 0377, 0xff, 0b1111111 (all 255 10 ) Normal operations between numbers “.” is the string concatenation operator, “x” the string multiplier operator

9 Perl: Scalar Variables

10 Interpolation Perl will “interpolate” scalar values in strings.

11 Perl: Scalar Variables Variables: Undefined variables have a standard value. 0 for numbers. Empty string for strings.

12 Perl: Array Variables Perl implements (C-style) arrays with the beginning character ‘@’ Arrays are automatically maintained. Individual members can be accessed by using the first character ‘$’ Creates lists with six elements and three undefined entries. $string[0] = “zero”; $string[1] = “one” $string[5] = “five”;

13 Perl: Array Variables Use pop, push, shift, unshift to add or remove elements at the end or the beginning of an array.

14 Perl: Input / Output

15 Perl uses file handles, including standard input and output. $line = The input comes with a newline character attached. You can remove this with the “chomp” command.

16 Perl Input / Output Can obtain an array of input lines until user types Control+D (unix) or Control+Z (windows): chomp(@lines = ;

17 Perl: Hashes Hash items contain keys and records. We look up a hash record by key. Key is a string Hash table itself starts out with a %.

18 Perl: Hashes


Download ppt "Perl COEN 351  Thomas Schwarz, S.J. 2006. Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles."

Similar presentations


Ads by Google