Introduction to Perl

Size: px
Start display at page:

Download "Introduction to Perl"

Transcription

1 Introduction to Perl Scott Hazelhurst August 2013

2 Introduction and Motivation Introduction and Motivation Practical Extraction and Report Language General language Intended for systems programming, scripting Popular with systems programmers & Web developers Relatively new language (ca. 1990) Big language support for concurrency and OO. Portable.

3 Introduction and Motivation Perl powerful and flexible language: Many devotees Many criticisms of the language Easy to write difficult-to-understand code. Focus on writing readable code (for yourself, others)

4 Introduction and Motivation Objectives Describe basic features of Perl Write simple Perl programs Use basic matching facilities Lots of resources: Books perldoc, info perl Assume: knowledge of programming, C-like language

5 Perl s Data Structures Perl s Data Structures I Perl is an imperative language. State is represented by a set of variables. Program is an ordered sequence of commands. Computation is accomplished by the execution of these commands in the specified order Will explore Perl s OO features later.

6 Perl s Data Structures Flexible (perhaps too flexible) language. Scalars: numbers, strings Arrays, lists Hash tables References Variables have a special prefatory character to indicate to which genre of variable (%, )

7 Perl s Data Structures Feature Warning Variables automatically declared Variables given default values Implicit type coercion common Meaning dependent on context Good idea to use the use strict; use warnings pragmas

8 Perl s Data Structures Scalar types Scalar types All scalar variables have a $ as prefix: e.g. $x, $year$, $etc. $c = 10; $f = 9/5* $c +32; $cname = Introduction to Perl ; print " Course $cname : size $c\n";

9 Perl s Data Structures String operations Interpolation Inside a double-quoted string, Perl does variable interpolation, and interprets escape characters print "Course $cname size \t $f\n;";

10 Perl s Data Structures String operations Interpolation Inside a double-quoted string, Perl does variable interpolation, and interprets escape characters print "Course $cname size \t $f\n;"; Not done inside single-quoted strings. print Course $cname size \t $f\n ;

11 Perl s Data Structures String operations Other string operations Concatenation:. $fruits = apples and pears ; $base = pies ; $full = $fruits. make. $base ; $full.= :. fruits ; Length of string: length. Substrings: substr Repeat operator: x Powerful & flexible string matching and processing regular expressions. Type conversion to and from integers as necessary!!?!!

12 Perl s Data Structures Artithmetic operations Arithmetic Operations The basic Perl arithmetic operations are: +, -, *, /, %, **. Default: floating point arithmetic There are many arithmetic procedures: int, sqrt,... Short-cuts: $x = 3; $x += $y +1; $x ++; --$y; Perl has many C-like features. eg.

13 Perl s Data Structures Truth and Logical operations Truth and Logical operations 1. Any string is true except for the empty string and 0 ; 2. Any number is true except for 0 3. Any reference is true 4. Any undefined value is false

14 Perl s Data Structures Truth and Logical operations Logical operators High binding Low binding && and or! not Short-circuit evaluation! Logical expressions returns the last value evaluated. e.g. 2 or 3 and 5 2 and (0 or 5) $a = 2

15 Perl s Data Structures Truth and Logical operations Relational operators Comparison Numeric String Equal, Not equal ==,!= eq, ne Less than (equal) <, <= lt, le Greater than (equal) >, >= gt, ge Comparison <=> cmp Smart matching ~~ ~~

16 Perl s Data Structures Truth and Logical operations File operators Example Name Example Name -e $a File Exists -T $a File is a text file -r $a Readable file -w $a Writable file -d $a File is a directory -f $a Regular file

17 Standard input and output Standard input and output Default: file handle STDIN associated with keyboard (input), STDOUT with console output. Input is line oriented.

18 Standard input and output Output print command by default sends output to STDOUT. print "Hello"; same as print STDOUT "Hello";

19 Standard input and output Input A reference to <STDIN> waits for input from console. data typed in is returned print "Enter the temp in C: "; $c = <STDIN>; print "Temperature in F is ". (9/5*$c+32);

20 Control Structures Making decisions Control structures Conditional if/else/elsif: if ($x < $y) {$x=1} else {$y=1}; unless: unless ($ok) { die "Error in file I/O"; } no explicit switch/case implicit through use of short-circuit (-e "f.dat") or ($numf++) ternary conditional operator cond? ex1 : ex2

21 Control Structures Making decisions Example unless (-e " data. dat ") { die " File data. dat not found " };

22 Control Structures Making decisions Example $c = $a cmp $b; if ($c ==0) { print " The strings are the same.\ n } elsif ($c <0) { print "$a comes before $b\n"; } else { print "$b comes before $a\n"; }

23 Control Structures Loops Loops while: while (cond} {... } for statement: C-style: for (init; condition; change) {... } foreach

24 Control Structures Loops Example while loop Read in a list of numbers terminated by 0. Compute the sum. $sum =0; $num =<STDIN >; while ( $num!= 0) { $sum = $sum + $num ; $num =<STDIN >; } print " Sum is $sum \n";

25 Control Structures Loops use strict ; my my $i; $j; for ( $i =1; $i <11; $i ++) { for ($j =0; $j <$i; $j ++) { print "*"; } print "\n"; }

26 Control Structures Loops use strict ; my $i; for ( $i =1; $i <11; $i ++) { print "*" x $i; print "\n"; }

27 Control Structures Other flow of control... Other flow of control... next, last continue and break scalar range operator:.. don t use unless you re an expert. goto don t use

28 Simple process control Simple process control Can execute Unix commands or executables using the backtick operator $today = date "+%C%y%m%d" ; print " Today is $today \n";

29 Simple process control Other system calls system Similar to backtick but returns return code $x = system ("ls"); print " Returned <$x >\n"; exec Similar to system, but does not wait for completion.

30 File operations File operations To read data from a file or write it to a file, use a file handle. Need to associate file handle with external file. File can be virtual could be a pipe.

31 File operations Files in general Files in General File handle is the Perl construct used to manipulate files Open it associate with external file or pipe Use it Close it

32 File operations Files in general open(dataf, "figs.dat") read

33 File operations Files in general open(dataf, "figs.dat") open(dataf, "<figs.dat") read read

34 File operations Files in general open(dataf, "figs.dat") open(dataf, "<figs.dat") open(dataf, ">figs.dat") read read write

35 File operations Files in general open(dataf, "figs.dat") open(dataf, "<figs.dat") open(dataf, ">figs.dat") open(dataf, ">>figs.dat") read read write append

36 File operations Files in general open(dataf, "figs.dat") read open(dataf, "<figs.dat") read open(dataf, ">figs.dat") write open(dataf, ">>figs.dat") append open(dataf, " output-pipe-cmd"); set up output filter

37 File operations Files in general open(dataf, "figs.dat") open(dataf, "<figs.dat") open(dataf, ">figs.dat") open(dataf, ">>figs.dat") open(dataf, " output-pipe-cmd"); up output filter read read write append set open(dataf, "input-pipe-cmd "); set up input filter

38 File operations Files in general open(dataf, "figs.dat") open(dataf, "<figs.dat") open(dataf, ">figs.dat") open(dataf, ">>figs.dat") open(dataf, " output-pipe-cmd"); up output filter read read write append set open(dataf, "input-pipe-cmd "); set up input filter

39 File operations Files in general open(dataf, "figs.dat") open(dataf, "<figs.dat") open(dataf, ">figs.dat") open(dataf, ">>figs.dat") open(dataf, " output-pipe-cmd"); up output filter read read write append set open(dataf, "input-pipe-cmd "); set up input filter To print to a file that is open for writing, use the related file handle in the print statement.

40 File operations Input from files Input from files Suppose that INP is a file handle. A reference to <INP> does the following: Returns the next line of input; Consumes the input in the case of a file, advances the file pointer to the next line of the file. NB: end-of-line marker read in.

41 File operations Input from files for ($i =0; $i <3; $i ++) { $x=<inp >; print "** $x ##" } Assuming that file contains apple, banana, cherry.

42 File operations Input from files for ($i =0; $i <3; $i ++) { $x=<inp >; print "** $x ##" } Assuming that file contains apple, banana, cherry. **apple ##**banana ##**cherry ##

43 File operations Input from files To add up the numbers in a file with three numbers. open (INP," nums. txt "); $x1 = <INP >; $x2 = <INP >; $x3 = <INP >; print " Answer is ". $x1 + $x2 + $x3 ; or open (INP," nums. txt "); print " Answer is ". ( < INP > + <INP > + <INP >);

44 File operations Input from files What s the difference between print " Answer is ". ( < INP > + <INP > + <INP >); and print " Answer is. ( < INP > + <INP > + <INP >) ";

45 File operations Input from files Add up odd numbers in file print " Enter the file name : "; $namef = < STDIN >; open (DATAF, $namef ); while ($x = <DATAF >) { if ($x % 2) { $sum = $sum + $x; } } close ( DATAF ); print " The sum is $sum \n";

46 File operations Input from files A common Perl idiom is open (DATAF, $namef ) or die " Can t open

47 File operations Implicit operands Implicit Operands Perl uses implicit operands extensively. We are told that this is a feature. The main culprit: $_ or $ARG Set (among other places) by reference to a file handle. Many operators use $ARG if not given explicit operator explicitly. The following prints out the contents of a file: while (<DATAF>) {print};

48 File operations Implicit operands Exercise Write a Perl program that reads integers from a file called nums.dat and counts how many numbers are less than zero between zero and 10 greater than or equal to 11 If there is no such file, your program should print an error message and halt.

49 Arrays/lists Arrays/lists Array variables are prefixed = (" Sun ", " Mon ", " Tue ", " Wed ", " Thu ", " F Arrays indexed from 0

50 Arrays/lists Arrays/lists Array variables are prefixed = (" Sun ", " Mon ", " Tue ", " Wed ", " Thu ", " F Arrays indexed from 0 Individual element are scalars: so $days[0]

51 Arrays/lists Common to use = (" Sun ", " Mon ", " Tue ", " Wed ", " foreach $d ) { print " Day $d\n"; }

52 Arrays/lists Quote words Short hand for arrays of = qw( Sun Mon Tue Wed Thu Fri Sat

53 program s Predefined variable array Contains the program s arguments values passed by the caller. If the program is run as follows:./example.pl apple pear contains those values $ARGV[0] is apple; $ARGV[3] is 2;

54 Arrays/lists Array semantics Expressions are evaluated in scalar or list context. Similar or identical expressions can evaluate to different things in different contexts.

55 Arrays/lists Array semantics Expressions are evaluated in scalar or list context. Similar or identical expressions can evaluate to different things in different contexts. Context determined by operation: LHS of assignment determines context Operators or functions may determine context

56 Arrays/lists Array context yields array $weekdays set to Mon.. is a one element array

57 Arrays/lists Array context yields array $weekdays set to Mon.. is a one element array Scalar context $numdays sets $numdays to 7

58 Arrays/lists Array context yields array $weekdays set to Mon.. is a one element array Scalar context $numdays sets $numdays to 7 $y = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat") sets $y to Sat

59 Arrays/lists Array context yields array $weekdays set to Mon.. is a one element array Scalar context $numdays sets $numdays to 7 $y = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat") sets $y to Sat $weekdays = $days[1..5] sets $weekdays to 5 $#days is 6 the highest index

60 Arrays/lists Useful functions push : adds something to the right of the array pop : removes the rightmost element of the array. shift/unshift sort: returns a sorted list by default string order ascending, but can be changed.

61 Arrays/lists Arrays are inherently 1D Need references to handle multi-dimensional arrays

62 Arrays/lists Asides Asides on strings = split ";", " 1;2;3 "; foreach $s (@x) { print "$s\n"; } chop, chomp. see regexes later

63 Hash tables Hash tables Unordered set of scalars which allows fast information retrieval: Elements accessed/indexed by a string value associated with it Variables prefixed by a %, e.g. %currency Individual elements are scalar: $currency["south Africa"]

64 Hash tables $currency [" South Africa "]="ZAR "; $currency [" Britain "] = " GBP ";

65 Hash tables Example %day2num = ("Sun",0, "Mon",1, "Tue",2, "Wed",3, "Thu",4, "Fri",5, "Sat",6) Better is %day2num= ("Sun"=>0, "Mon"=>1, "Tue"=>2, "Wed"=>3, "Thu"=>4, "Fri"=>5, "Sat"=>6) Referred to as $day2num{"wed"}

66 Hash tables Useful hash operations keys returns list of keys in hash table. Order non-deterministic.

67 Hash tables Useful hash operations keys returns list of keys in hash table. Order non-deterministic. values returns list values stored in the hash table. Order of no significance.

68 Hash tables Useful hash operations keys returns list of keys in hash table. Order non-deterministic. values returns list values stored in the hash table. Order of no significance. sort keys %table lists the keys in lexicographic order

69 Hash tables Example # read in from file while ($name = <INP>) { $reg = <INP>; $carreg{$name} = $reg; } # print out in order of name foreach $n (sort keys %carreg) { print "Car reg of $n is $carreg{$n} \n"; }

70 Hash tables Can also tell sort how to sort: sort {$a <=> $b} list sorts the list in numeric order. sort {$table{$a} cmp $table{$b}} keys %tabl sorts the keys so that corresponding hash table elements are in order

71 Hash tables #print out in order of car reg foreach $n (sort {$carreg{$a} cmp $carreg{$b}} keys %carreg) { print "$carreg{$n} owned by $n\n"; }

72 Procedures Procedures Perl has procedures but its parameter passing mechanism is poor. Suppose we have a procedure plus that adds up two numbers. Called: $x = &plus($a, $b); where $a and $b are the parameters. Call by value semantics

73 Procedures Declaring a subroutine To declare a subroutine: sub NAME BLOCK e.g. sub printhead { print "Name Age Number Balance\n"; }... &printhead();

74 Procedures Parameters Procedures have one formal The values of the actual parameter are given to the formal parameter a list local to the procedure. sub plus { sub plus { $x = $_[0]; my ($x,$y) $y = $_[1]; return $x+$y; return $x + $y; } }

75 Procedures A common idiom uses shift sub plus { $x = $y = return $x + $y; }

76 Procedures Example A procedure to add up a list: sub addlist {$sum = 0; foreach $num (@_) {$sum += $num}; return $sum;} sub proclist { my ($f1,$f2,@nums) foreach $n (@nums) {$sum = $sum+$n; } return ($f1*$f2*$sum); } $x = &addlist(1,2,3,5,6,9); $y = &proclist(3,4,1,1,0,2);

77 Procedures The following does not work (s sub dotprod { (@a,@b) = = (4,5,6); &dotprod(@x,@y);

78 Procedures Formal parameter is an unstructured list (possible danger in passing multiple lists as parameters) Forward declarations: sub addlist; Telling Perl that addlist is a procedure which will be declared elsewhere. Can have anonymous procedures that get assigned to variables. Weakness in parameter system can be overcome by using references. Default: all variables are global wherever defined. This is even recognised by the Perl community to be a Bad Thing Declare variables local inside procedures. Best way: prefix first use of variable in a procedure with with my. Lexical scoping.

79 References References References are mechanisms for a variable to refer to something, e.g. (1) another variable; (2) a piece of data; (3); a function Symbolic references Can turn a string into a variable $x = 123; $y = "x"; $$y = 5; print $x;

80 References Hard references Can use the \ operator to dereference a variable, and -> to = (10,20,30,40,50); $x = \@a; for $e ) { print "$e\n"; } print $x->[0];

81 References Call by reference sub count { my ( $fname, $rcount ) chomp $fname ; unless (-T $fname ) { return ; } open (FINP, $fname ); while (<FINP >) { $$rcount ++ } close ( FINP ); }

82 = ls -1 $ARGV [0] ; $n = 0; for $f ) { & count ($f,\ $n ); } print " Total number of lines is $n\ n";

83 References Passing multiple arrays sub dotprod { ($a,$b)=@_;... = = (4,5,6); &dotprod(\@x,\@y); Note that only scalars are passed.

84 References Refs to anonymous arrays and hashes Square brackets creates an array returns a reference $a = [ 10, 20, 30, 40]; = [ 10, 20, 30, 40]; Curly braces creates a hash returns a reference $day = {"sun"=>0, "mon"=>1, "tues"=>...}

85 Modules Modules A module is a collection of code, data structures that can be used as a library Often see it in OO programming Magic word is use use IO; To access something is in a module use ::. So, module::thing Modules can be nested.

86 Modules Example use IO :: Compress :: Bzip2 ; IO :: Compress :: Bzip2 :: bzip2 ("do.pl", "do.pl.bz

87 Modules Example use IO :: Compress :: Bzip2 ; IO :: Compress :: Bzip2 :: bzip2 Can also import specific things ("do.pl", "do.pl.bz use IO :: Compress :: Bzip2 qw( bzip2 $Bzip2Error ); unless ( bzip2 ("do.plx ", "do.pl.bz2 ")) { warn " Compression failed returning : $Bzip2 }

88 Objects Objects Data structures which contain data, know functions that can apply to them; anonymous accessed through references typically organised in classes

89 Objects use Bio :: Seq ; $seqio = Bio :: SeqIO -> new ( - format => embl, -file $seqobj = $seqio - > next_ seq (); $seqstr = $seqobj -> seq (); $seqstr = $seqobj -> subseq features = $seqobj - > get_ SeqFeatures (); foreach my $feat features ) { print " Feature ",$feat -> primary_tag, " starts ",$feat -> start, " ends ", $feat ->end," strand ",$feat -> strand,"\n"; }

90 Regular expressions Regular expressions, matching, and more Perl s regular expression support powerful concise way of describing a set of strings. Typical: a command uses a regular expression to process some argument. Example: split uses a regex to split a string $line = "Gauteng;Johannesburg GP = split("[ ;]", $line); ($prov, $capital,$reg, $pop) = split("[ ;] ", $line);

91 Regular expressions Specifying Regular Expressions Most characters stand for themselves: F Fred 6312

92 Regular expressions Specifying Regular Expressions Most characters stand for themselves: F Fred 6312 \ ( ) [ { ^ $ * +?. are metacharacters (have special meaning) escape with a backslash for the chars: Fred stands for the string (Fred)

93 Regular expressions Specifying Regular Expressions Most characters stand for themselves: F Fred 6312 \ ( ) [ { ^ $ * +?. are metacharacters (have special meaning) escape with a backslash for the chars: Fred stands for the string (Fred) To group things together, use parentheses.

94 Regular expressions Specifying Regular Expressions Most characters stand for themselves: F Fred 6312 \ ( ) [ { ^ $ * +?. are metacharacters (have special meaning) escape with a backslash for the chars: Fred stands for the string (Fred) To group things together, use parentheses. To specify alternatives, use (green red) apples stands for green apples or red apples

95 Regular expressions Specifying Regular Expressions Most characters stand for themselves: F Fred 6312 \ ( ) [ { ^ $ * +?. are metacharacters (have special meaning) escape with a backslash for the chars: Fred stands for the string (Fred) To group things together, use parentheses. To specify alternatives, use (green red) apples stands for green apples or red apples

96 Regular expressions Specifying Regular Expressions A list of characters in square brackets matches any of the characters. [YyNn] matches any of an upper or lower case y or n. [A-Za-z0-9] is all the alphanumeric characters

97 Regular expressions \n new line; \t tab; \s a whitespace;

98 Regular expressions \n new line; \t tab; \s a whitespace; \d digit; \D non-digit;

99 Regular expressions \n new line; \t tab; \s a whitespace; \d digit; \D non-digit; \w a word charater, \W a non-word character

100 Regular expressions \n new line; \t tab; \s a whitespace; \d digit; \D non-digit; \w a word charater, \W a non-word character. anything but a \n

101 Regular expressions \n new line; \t tab; \s a whitespace; \d digit; \D non-digit; \w a word charater, \W a non-word character. anything but a \n m{3} stands for mmm (map){2,3} stands for mapmap or mapmapmap m* stands for 0 or more m s

102 Regular expressions \n new line; \t tab; \s a whitespace; \d digit; \D non-digit; \w a word charater, \W a non-word character. anything but a \n m{3} stands for mmm (map){2,3} stands for mapmap or mapmapmap m* stands for 0 or more m s m+ stands for 1 or more m s

103 Regular expressions \n new line; \t tab; \s a whitespace; \d digit; \D non-digit; \w a word charater, \W a non-word character. anything but a \n m{3} stands for mmm (map){2,3} stands for mapmap or mapmapmap m* stands for 0 or more m s m+ stands for 1 or more m s Many others. Rules long and complex.

104 Regular expressions Processing with regular expressions Various commands that allow finding a pattern matching a regular expression in a string; extracting out the regular expression; substituting; or other modification e.g. matching, substitution, translation, substitution.

105 Regular expressions Splitting up input split(pat,string) Takes the input string and splits the string wherever the pattern pat occurs.

106 Regular expressions Splitting up input split(pat,string) Takes the input string and splits the string wherever the pattern pat occurs. returns a list of strings as a result can choose whether the split pattern is part of the returned string or not

107 Regular expressions Splitting up input split(pat,string) Takes the input string and splits the string wherever the pattern pat occurs. returns a list of strings as a result can choose whether the split pattern is part of the returned string or not $x = split /\* ::/, $c processes the string $c, splits it wherever a * or :: appear, and returns the split list. So, if $c="dat: 23 * Mon: 11; LgA -632 ::: LgB -217* a", $x=?

108 Regular expressions Matching m/regexpr/ returns true if the regular expression matches $_.

109 Regular expressions Matching m/regexpr/ returns true if the regular expression matches $_. The m is optional in most cases (unless slash in string) m-/apple-

110 Regular expressions Matching m/regexpr/ returns true if the regular expression matches $_. The m is optional in most cases (unless slash in string) m-/apple- To match a particular string use the binding operator: =~ $inp =~ m/(pascal) (\WC\W) (C\+\+)/;

111 Regular expressions Matching m/regexpr/ returns true if the regular expression matches $_. The m is optional in most cases (unless slash in string) m-/apple- To match a particular string use the binding operator: =~ $inp =~ m/(pascal) (\WC\W) (C\+\+)/; A number of modifiers available: i (case insensitive) g (global) Count number of matches in a string: while ($inp =~ m/(pascal) (\WC\W) (C\+\+)/g) { $wrd++ }

112 Regular expressions Extracting patterns * Can refer to and extract out subexpressions matched $1, $2,... To find a repeat m/\b(\w+)\s+\1/ To extract out while ($line = <INP>) { $line =~ m/(\w+)\s+(\w+)/; $name = $1; $reg = $2; $carreg{$name}=$reg; } Look for repeats:

113 Regular expressions Substitution s/regexpra/regexprb/ substitutes regular expression A by regular expression B. Default string processed is $. s/apple/orange/; Replaces the first occurrence of Apple in $ with Orange Similar modifiers to m: i, g,... Use the binder operator to choose the string chosen: $name = "Alan Turing"; $name =~ s/(\w)\w*/\1\./; $c = ($name =~ s/(\w)\w*/\1\./); $c = ($name =~ s/(\w)\w*/\1\./g);

114 Regular expressions Translation Use the tr or y operator. Operates on strings, rather than regular expressions. tr/range1/range2/ replaces any character in range1 and replaces it with the corresponding character in range2. $c =~ tr/a-z/a-z/ change every character in $c to uppercase. $cnt = $c =~ tr/a-z/a-z/ sets $cnt to the number of lower case letters in $c.

115 And more And more maths functions more sophisticated I/O lots of built in variables: e.g. \$NR modules, OO IPC, networking process control

Pathologically Eclectic Rubbish Lister

Pathologically Eclectic Rubbish Lister Pathologically Eclectic Rubbish Lister 1 Perl Design Philosophy Author: Reuben Francis Cornel perl is an acronym for Practical Extraction and Report Language. But I guess the title is a rough translation

More information

PERL Scripting - Course Contents

PERL Scripting - Course Contents PERL Scripting - Course Contents Day - 1 Introduction to PERL Comments Reading from Standard Input Writing to Standard Output Scalar Variables Numbers and Strings Use of Single Quotes and Double Quotes

More information

(Refer Slide Time: 01:12)

(Refer Slide Time: 01:12) Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #22 PERL Part II We continue with our discussion on the Perl

More information

CSCI 4152/6509 Natural Language Processing. Perl Tutorial CSCI 4152/6509. CSCI 4152/6509, Perl Tutorial 1

CSCI 4152/6509 Natural Language Processing. Perl Tutorial CSCI 4152/6509. CSCI 4152/6509, Perl Tutorial 1 CSCI 4152/6509 Natural Language Processing Perl Tutorial CSCI 4152/6509 Vlado Kešelj CSCI 4152/6509, Perl Tutorial 1 created in 1987 by Larry Wall About Perl interpreted language, with just-in-time semi-compilation

More information

1. Introduction. 2. Scalar Data

1. Introduction. 2. Scalar Data 1. Introduction What Does Perl Stand For? Why Did Larry Create Perl? Why Didn t Larry Just Use Some Other Language? Is Perl Easy or Hard? How Did Perl Get to Be So Popular? What s Happening with Perl Now?

More information

Scripting Languages Perl Basics. Course: Hebrew University

Scripting Languages Perl Basics. Course: Hebrew University Scripting Languages Perl Basics Course: 67557 Hebrew University אליוט יפה Jaffe Lecturer: Elliot FMTEYEWTK Far More Than Everything You've Ever Wanted to Know Perl Pathologically Eclectic Rubbish Lister

More information

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295 Perl Scripting Duration: 4 Days Price: $2295 Discounts: We offer multiple discount options. Click here for more info. Delivery Options: Attend face-to-face in the classroom, remote-live or on-demand streaming.

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

CS 230 Programming Languages

CS 230 Programming Languages CS 230 Programming Languages 09 / 16 / 2013 Instructor: Michael Eckmann Today s Topics Questions/comments? Continue Syntax & Semantics Mini-pascal Attribute Grammars More Perl A more complex grammar Let's

More information

Perl. Many of these conflict with design principles of languages for teaching.

Perl. Many of these conflict with design principles of languages for teaching. Perl Perl = Practical Extraction and Report Language Developed by Larry Wall (late 80 s) as a replacement for awk. Has grown to become a replacement for awk, sed, grep, other filters, shell scripts, C

More information

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Indian Institute of Technology Kharagpur PERL Part II Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Kharagpur, INDIA Lecture 22: PERL Part II On completion, the student will be able

More information

CMSC 331 Final Exam Fall 2013

CMSC 331 Final Exam Fall 2013 CMSC 331 Final Exam Fall 2013 Name: UMBC username: You have two hours to complete this closed book exam. Use the backs of these pages if you need more room for your answers. Describe any assumptions you

More information

Regular expressions and case insensitivity

Regular expressions and case insensitivity Regular expressions and case insensitivity As previously mentioned, you can make matching case insensitive with the i flag: /\b[uu][nn][ii][xx]\b/; /\bunix\b/i; # explicitly giving case folding # using

More information

Perl. Interview Questions and Answers

Perl. Interview Questions and Answers and Answers Prepared by Abhisek Vyas Document Version 1.0 Team, www.sybaseblog.com 1 of 13 Q. How do you separate executable statements in perl? semi-colons separate executable statements Example: my(

More information

Regular expressions and case insensitivity

Regular expressions and case insensitivity Regular expressions and case insensitivity As previously mentioned, you can make matching case insensitive with the i flag: /\b[uu][nn][ii][xx]\b/; # explicitly giving case folding /\bunix\b/i; # using

More information

A control expression must evaluate to a value that can be interpreted as true or false.

A control expression must evaluate to a value that can be interpreted as true or false. Control Statements Control Expressions A control expression must evaluate to a value that can be interpreted as true or false. How a control statement behaves depends on the value of its control expression.

More information

Outline. CS3157: Advanced Programming. Feedback from last class. Last plug

Outline. CS3157: Advanced Programming. Feedback from last class. Last plug Outline CS3157: Advanced Programming Lecture #2 Jan 23 Shlomo Hershkop shlomo@cs.columbia.edu Feedback Introduction to Perl review and continued Intro to Regular expressions Reading Programming Perl pg

More information

COMS 3101 Programming Languages: Perl. Lecture 2

COMS 3101 Programming Languages: Perl. Lecture 2 COMS 3101 Programming Languages: Perl Lecture 2 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Control Flow (continued) Input / Output Subroutines Concepts:

More information

More Perl. CS174 Chris Pollett Oct 25, 2006.

More Perl. CS174 Chris Pollett Oct 25, 2006. More Perl CS174 Chris Pollett Oct 25, 2006. Outline Loops Arrays Hashes Functions Selection Redux Last day we learned about how if-else works in Perl. Perl does not have a switch statement Like Javascript,

More information

T-( )-MALV, Natural Language Processing The programming language Perl

T-( )-MALV, Natural Language Processing The programming language Perl T-(538 725)-MALV, Natural Language Processing The programming language Perl Hrafn Loftsson 1 Hannes Högni Vilhjálmsson 1 1 School of Computer Science, Reykjavik University September 2010 Outline 1 Perl

More information

Perl. Perl. Perl. Which Perl

Perl. Perl. Perl. Which Perl Perl Perl Perl = Practical Extraction and Report Language Developed by Larry Wall (late 80 s) as a replacement for awk. Has grown to become a replacement for awk, sed, grep, other filters, shell scripts,

More information

Scripting Languages. Diana Trandabăț

Scripting Languages. Diana Trandabăț Scripting Languages Diana Trandabăț Master in Computational Linguistics - 1 st year 2017-2018 Today s lecture What is Perl? How to install Perl? How to write Perl progams? How to run a Perl program? perl

More information

8/13/ /printqp.php?heading=II BSc [ ], Semester III, Allied: COMPUTER PROGRAMMING-PERL -309C&qname=309C

8/13/ /printqp.php?heading=II BSc [ ], Semester III, Allied: COMPUTER PROGRAMMING-PERL -309C&qname=309C Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Reaccredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated 'A'

More information

Lecture 2: Programming in Perl: Introduction 1

Lecture 2: Programming in Perl: Introduction 1 Lecture 2: Programming in Perl: Introduction 1 Torgeir R. Hvidsten Professor Norwegian University of Life Sciences Guest lecturer Umeå Plant Science Centre Computational Life Science Cluster (CLiC) 1 This

More information

Classnote for COMS6100

Classnote for COMS6100 Classnote for COMS6100 Yiting Wang 3 November, 2016 Today we learn about subroutines, references, anonymous and file I/O in Perl. 1 Subroutines in Perl First of all, we review the subroutines that we had

More information

COP4020 Programming Assignment 1 - Spring 2011

COP4020 Programming Assignment 1 - Spring 2011 COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative programming language Micro-PL. To execute Mirco-PL code we translate the code to

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list.

They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list. Arrays Perl arrays store lists of scalar values, which may be of different types. They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list. A list literal

More information

Beginning Perl. Mark Senn. September 11, 2007

Beginning Perl. Mark Senn. September 11, 2007 GoBack Beginning Perl Mark Senn September 11, 2007 Overview Perl is a popular programming language used to write systen software, text processing tools, World Wide Web CGI programs, etc. It was written

More information

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP Chapter 11 Introduction to PHP 11.1 Origin and Uses of PHP Developed by Rasmus Lerdorf in 1994 PHP is a server-side scripting language, embedded in XHTML pages PHP has good support for form processing

More information

Introduction to Perl. Perl Background. Sept 24, 2007 Class Meeting 6

Introduction to Perl. Perl Background. Sept 24, 2007 Class Meeting 6 Introduction to Perl Sept 24, 2007 Class Meeting 6 * Notes on Perl by Lenwood Heath, Virginia Tech 2004 Perl Background Practical Extraction and Report Language (Perl) Created by Larry Wall, mid-1980's

More information

Indian Institute of Technology Kharagpur. PERL Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

Indian Institute of Technology Kharagpur. PERL Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Indian Institute of Technology Kharagpur PERL Part III Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Kharagpur, INDIA Lecture 23: PERL Part III On completion, the student will be able

More information

Bourne Shell Reference

Bourne Shell Reference > Linux Reviews > Beginners: Learn Linux > Bourne Shell Reference Bourne Shell Reference found at Br. David Carlson, O.S.B. pages, cis.stvincent.edu/carlsond/cs330/unix/bshellref - Converted to txt2tags

More information

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi Titolo presentazione Piattaforme Software per la Rete sottotitolo BASH Scripting Milano, XX mese 20XX A.A. 2016/17, Alessandro Barenghi Outline 1) Introduction to BASH 2) Helper commands 3) Control Flow

More information

COMS 3101 Programming Languages: Perl. Lecture 1

COMS 3101 Programming Languages: Perl. Lecture 1 COMS 3101 Programming Languages: Perl Lecture 1 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl What is Perl? Perl is a high level language initially developed as a scripting

More information

COMP284 Scripting Languages Lecture 2: Perl (Part 1) Handouts

COMP284 Scripting Languages Lecture 2: Perl (Part 1) Handouts COMP284 Scripting Languages Lecture 2: Perl (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Hands-On Perl Scripting and CGI Programming

Hands-On Perl Scripting and CGI Programming Hands-On Course Description This hands on Perl programming course provides a thorough introduction to the Perl programming language, teaching attendees how to develop and maintain portable scripts useful

More information

String Computation Program

String Computation Program String Computation Program Reference Manual Scott Pender scp2135@columbia.edu COMS4115 Fall 2012 10/31/2012 1 Lexical Conventions There are four kinds of tokens: identifiers, keywords, expression operators,

More information

Perl and Python ESA 2007/2008. Eelco Schatborn 27 September 2007

Perl and Python ESA 2007/2008. Eelco Schatborn 27 September 2007 Perl and Python ESA 2007/2008 Eelco Schatborn eelco@os3.nl 27 September 2007 ESA: Perl Vandaag: 1. Perl introduction 2. Basic Perl: types, variables, statements,... 3. Object Oriented Perl 4. Documentation

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

What is PERL?

What is PERL? Perl For Beginners What is PERL? Practical Extraction Reporting Language General-purpose programming language Creation of Larry Wall 1987 Maintained by a community of developers Free/Open Source www.cpan.org

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 9/11/2013 Textual data processing (Perl) 1 Announcements If you did not get a PIN to enroll, contact Stephanie Meik 2 Outline Perl Basics (continued) Regular Expressions

More information

Shells and Shell Programming

Shells and Shell Programming Shells and Shell Programming 1 Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed

More information

CSCI 1061U Programming Workshop 2. C++ Basics

CSCI 1061U Programming Workshop 2. C++ Basics CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output

More information

Shells & Shell Programming (Part B)

Shells & Shell Programming (Part B) Shells & Shell Programming (Part B) Software Tools EECS2031 Winter 2018 Manos Papagelis Thanks to Karen Reid and Alan J Rosenthal for material in these slides CONTROL STATEMENTS 2 Control Statements Conditional

More information

Programming Perls* Objective: To introduce students to the perl language.

Programming Perls* Objective: To introduce students to the perl language. Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard Things Possible Perl is a language for easily manipulating

More information

Examples of Using the ARGV Array. Loop Control Operators. Next Operator. Last Operator. Perl has three loop control operators.

Examples of Using the ARGV Array. Loop Control Operators. Next Operator. Last Operator. Perl has three loop control operators. Examples of Using the ARGV Array # mimics the Unix echo utility foreach (@ARGV) { print $_ ; print \n ; # count the number of command line arguments $i = 0; foreach (@ARGV) { $i++; print The number of

More information

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi Bash Scripting Alessandro Barenghi Dipartimento di Elettronica, Informazione e Bioingegneria Politecnico di Milano alessandro.barenghi - at - polimi.it April 28, 2015 Introduction The bash command shell

More information

Should you know scanf and printf?

Should you know scanf and printf? C-LANGUAGE INPUT & OUTPUT C-Language Output with printf Input with scanf and gets_s and Defensive Programming Copyright 2016 Dan McElroy Should you know scanf and printf? scanf is only useful in the C-language,

More information

Organization of Programming Languages CS3200/5200N. Lecture 11

Organization of Programming Languages CS3200/5200N. Lecture 11 Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages

More information

Language Reference Manual

Language Reference Manual TAPE: A File Handling Language Language Reference Manual Tianhua Fang (tf2377) Alexander Sato (as4628) Priscilla Wang (pyw2102) Edwin Chan (cc3919) Programming Languages and Translators COMSW 4115 Fall

More information

Beginning Perl for Bioinformatics. Steven Nevers Bioinformatics Research Group Brigham Young University

Beginning Perl for Bioinformatics. Steven Nevers Bioinformatics Research Group Brigham Young University Beginning Perl for Bioinformatics Steven Nevers Bioinformatics Research Group Brigham Young University Why Use Perl? Interpreted language (quick to program) Easy to learn compared to most languages Designed

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Basic Linux (Bash) Commands

Basic Linux (Bash) Commands Basic Linux (Bash) Commands Hint: Run commands in the emacs shell (emacs -nw, then M-x shell) instead of the terminal. It eases searching for and revising commands and navigating and copying-and-pasting

More information

Introduction to Perl. c Sanjiv K. Bhatia. Department of Mathematics & Computer Science University of Missouri St. Louis St.

Introduction to Perl. c Sanjiv K. Bhatia. Department of Mathematics & Computer Science University of Missouri St. Louis St. Introduction to Perl c Sanjiv K. Bhatia Department of Mathematics & Computer Science University of Missouri St. Louis St. Louis, MO 63121 Contents 1 Introduction 1 2 Getting started 1 3 Writing Perl scripts

More information

Shells and Shell Programming

Shells and Shell Programming Shells and Shell Programming Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012 Cisco IOS Shell Last Updated: December 14, 2012 The Cisco IOS Shell (IOS.sh) feature provides shell scripting capability to the Cisco IOS command-lineinterface (CLI) environment. Cisco IOS.sh enhances

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 6/7/2012 Textual data processing (Perl) CS 5142 Cornell University 9/7/13 1 Administrative Announcements Homework 2 due Friday at 6pm. First prelim 9/27, Review on

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

CSC Web Programming. Introduction to JavaScript

CSC Web Programming. Introduction to JavaScript CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

15.1 Origins and Uses of Ruby

15.1 Origins and Uses of Ruby 15.1 Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in 1996 - Use spread rapidly in Japan - Use is now growing in part because of its use in Rails - A pure object-oriented purely interpreted

More information

Data Types The ML Type System

Data Types The ML Type System 7 Data Types 7.2.4 The ML Type System The following is an ML version of the tail-recursive Fibonacci function introduced Fibonacci function in ML in Section 6.6.1: EXAMPLE 7.96 1. fun fib (n) = 2. let

More information

Welcome to Research Computing Services training week! November 14-17, 2011

Welcome to Research Computing Services training week! November 14-17, 2011 Welcome to Research Computing Services training week! November 14-17, 2011 Monday intro to Perl, Python and R Tuesday learn to use Titan Wednesday GPU, MPI and profiling Thursday about RCS and services

More information

ARRAYS(II Unit Part II)

ARRAYS(II Unit Part II) ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful

More information

Outline. Introduction to Perl. Why use scripting languages? What is expressiveness. Why use Java over C

Outline. Introduction to Perl. Why use scripting languages? What is expressiveness. Why use Java over C Outline Introduction to Perl Grégory Mounié Scripting Languages Perl 2012-10-11 jeu. Basics Advanced 1 / 30 2 / 30 Why use scripting languages? What is expressiveness Why use Java over C Memory management

More information

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013 Bash scripting Tutorial Super User Programming & Scripting 22 March 2013 Hello World Bash Shell Script First you need to find out where is your bash interpreter located. Enter the following into your command

More information

Introduction to Perl Session 6. special variables subroutines Introduction to Perl

Introduction to Perl Session 6. special variables subroutines Introduction to Perl 1.0.1.8.6 Introduction to Perl Session 6 special variables subroutines 6/17/2008 1.0.1.8.6 - Introduction to Perl - Special Variables and Subroutines 1 I/O Recap file handles are created using open(f,$file);

More information

9.1 Origins and Uses of Perl

9.1 Origins and Uses of Perl 9.1 Origins and Uses of Perl - Began in the late 1980s as a more powerful replacement for the capabilities of awk (text file processing) and sh (UNIX system administration) - Now includes sockets for communications

More information

BASH and command line utilities Variables Conditional Commands Loop Commands BASH scripts

BASH and command line utilities Variables Conditional Commands Loop Commands BASH scripts BASH and command line utilities Variables Conditional Commands Loop Commands BASH scripts SCOMRED, October 2018 Instituto Superior de Engenharia do Porto (ISEP) Departamento de Engenharia Informática(DEI)

More information

Bamuengine.com. Chapter 14. Perl The Mater Manipulator

Bamuengine.com. Chapter 14. Perl The Mater Manipulator Chapter 14. Perl The Mater Manipulator Introduciton The following sections tell you what Perl is, the variables and operators in perl, the string handling functions. The chapter also discusses file handling

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

A shell can be used in one of two ways:

A shell can be used in one of two ways: Shell Scripting 1 A shell can be used in one of two ways: A command interpreter, used interactively A programming language, to write shell scripts (your own custom commands) 2 If we have a set of commands

More information

Modularity and Reusability I. Functions and code reuse

Modularity and Reusability I. Functions and code reuse Modularity and Reusability I Functions and code reuse Copyright 2006 2009 Stewart Weiss On being efficient When you realize that a piece of Perl code that you wrote may be useful in future programs, you

More information

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

More information

Subroutines. Subroutines. The Basics. aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc.

Subroutines. Subroutines. The Basics. aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc. Subroutines Subroutines aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc We ll just say Subroutines. "Functions" generally means built-in functions perldoc perlsub The Basics

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 9/20/2013 Context and Modules (Perl) Scripting as Glue 1 Outline Programming in the large Scripting as glue 2 Modules Module = file p/q.pm that starts with declaration

More information

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

C# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals

C# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals C# Types Industrial Programming Lecture 3: C# Fundamentals Industrial Programming 1 Industrial Programming 2 Value Types Memory location contains the data. Integers: Signed: sbyte, int, short, long Unsigned:

More information

JVM (java) compiler. A Java program is either a library of static methods (functions) or a data type definition

JVM (java) compiler. A Java program is either a library of static methods (functions) or a data type definition Programming Model Basic Structure of a Java Program The Java workflow editor (Code) P.java compiler (javac) P.class JVM (java) output A Java program is either a library of static methods (functions) or

More information

An Introduction to Scheme

An Introduction to Scheme An Introduction to Scheme Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Stéphane Ducasse 1 Scheme Minimal Statically scoped Functional Imperative Stack manipulation Specification

More information

Chapter 3. Basics in Perl. 3.1 Variables and operations Scalars Strings

Chapter 3. Basics in Perl. 3.1 Variables and operations Scalars Strings Chapter 3 Basics in Perl 3.1 Variables and operations 3.1.1 Scalars 2 $hello = "Hello World!"; 3 print $hello; $hello is a scalar variable. It represents an area in the memory where you can store data.

More information

Functional Programming Languages (FPL)

Functional Programming Languages (FPL) Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional

More information

Industrial Programming

Industrial Programming Industrial Programming Lecture 3: C# Fundamentals Industrial Programming 1 C# Types Industrial Programming 2 Value Types Memory location contains the data. Integers: Signed: sbyte, int, short, long Unsigned:

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

The Warhol Language Reference Manual

The Warhol Language Reference Manual The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming

More information

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

More information

Perl basics: a concise guide

Perl basics: a concise guide Perl basics: a concise guide Version 8 October 6, 2006 Copyright 2006 Paul M. Hoffman. Some rights reserved. This work is made available under a Creative Commons license see http://creativecommons.org/licenses/by/2.5/

More information

PHP. Interactive Web Systems

PHP. Interactive Web Systems PHP Interactive Web Systems PHP PHP is an open-source server side scripting language. PHP stands for PHP: Hypertext Preprocessor One of the most popular server side languages Second most popular on GitHub

More information

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

More information