Week 4. Week 4 Goals & Reading. Strict pragma P24H: Hour 8: Making a stricter Perl PP: Ch 6 (using the strict pragma)

Size: px
Start display at page:

Download "Week 4. Week 4 Goals & Reading. Strict pragma P24H: Hour 8: Making a stricter Perl PP: Ch 6 (using the strict pragma)"

Transcription

1 Week 4 Week 4 Goals & Reading Strict pragma P24H: Hour 8: Making a stricter Perl PP: Ch 6 (using the strict pragma) Regular Expressions P24H: Hour 6, Hour 9: Transliteration PP: Ch10, Ch15 Special variables complete list at (its long and scary) PP Sorting P24H: Hour 4 (reordering arrays) Biol Practical Biocomputing 1

2 Strict Syntax Why? Perl's ability to create variables on-the-fly is a two edged sword. simple programs can be written extremely quickly typographical errors are hard to detect What does "use strict;" require? All variables must be declared with "my" No "barewords" except as hash keys. All other barewords must correspond to functions No "symbolic references" X $foo = "some stuff; $var_name = "foo"; print $$var_name; # prints "some stuff" Biol Practical Biocomputing 2

3 Strict Syntax # read the file line-by-line count the number of reads and total length $line_num = 0; while ( $line = <> ) { # remove the newline character chomp $line; # The counts of the four bases at each position of the sequence are each # stored in separate arrays. An additional holds all other # characters if ( $line_num % 4 == 1 ) { # the second line is the sequence line #print "$line_num: $line:\n"; # split the sequence into an array of characters and increment the count # arrays for each = split "", $line; foreach $i ( 0.. $#base ) { if ( $base[$i] eq 'A' ) { $A[ $i ]++; Biol Practical Biocomputing 3

4 Strict Syntax after adding use strict; Global symbol "$line_num" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 21. Global symbol "$line" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 22. Global symbol "$line" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 24. Global symbol "$line_num" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 30. Global symbol requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 36. Global symbol "$line" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 36. Global symbol "$i" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 37. Global symbol requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 37. Global symbol requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 38. Global symbol "$i" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 38. Global symbol requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 39. Global symbol "$i" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 39. Global symbol requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 41. Global symbol "$i" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 41. Global symbol requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 42. Global symbol "$i" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 42. Global symbol requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 44. Global symbol "$i" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 44. Global symbol requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 45. Global symbol "$i" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 45. Global symbol requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 47. Global symbol "$i" requires explicit package name at C:/Users/mgribsko/workspace/work/2016perl/hw2_key.pl line 47. Biol Practical Biocomputing 4

5 Strict Syntax # read the file line-by-line count the number of reads and total length my $line_num = 0; while ( my $line = <> ) { # remove the newline character chomp $line; # The counts of the four bases at each position of the sequence are each # stored in separate arrays. An additional holds all other # characters if ( $line_num % 4 == 1 ) { # the second line is the sequence line #print "$line_num: $line:\n"; # split the sequence into an array of characters and increment the count # arrays for each position = split "", $line; foreach $i ( 0.. $#base ) { if ( $base[$i] eq 'A' ) { $A[ $i ]++; Biol Practical Biocomputing 5

6 Strict Syntax declare variable using my location of my determines scope variable is defined only within the nearest {. Loop variables defined inside loop, not outside global variables, in main program, are defined everywhere declared outside of all { # read the file line-by-line count the number of reads and total length ); = (); my $line_num = 0; while ( my $line = <> ) { # remove the newline character chomp $line; = split "", $line; foreach $i ( 0.. $#base ) { if ( $base[$i] eq 'A' ) { $A[ $i ]++; while ) { $na = print "$na\t$nc\t$ng\t$nt\t$frac_at\t$frac_gc\n"; Biol Practical Biocomputing 6

7 Style and Strict syntax From now on (for homework) Always use strict always declare all variables (even in main program) with "my" Scripts should have no errors or warnings with perl w use warnings; does the same Explicitly pass and return values to/from subroutines All subroutine variables must be local (declared with "my") Biol Practical Biocomputing 7

8 Regular Expressions (regex, re) Finding and replacing text (pattern matching) One of the most powerful features of Perl A tool for parsing and manipulating text parsing: identifying and labeling pieces of text e.g., noun verb subject object for english e.g., sequence, organism, gene name, etc., for bioinformatics Regular expressions are often cryptic always include a comment explaining what the regex does Biol Practical Biocomputing 8

9 Regular Expressions Three operations The "regular expression" (regex) describes what kind of string you are looking for, you can use the regex to Find (match) find a particular piece of text Replace (substitute) find a piece of test and change it Translate change every example of something in a text Biol Practical Biocomputing 9

10 Regular Expressions The basic idea: Regular expression uses the =~ operator (string binding operator) Expression evaluates to true or false $string =~ m/pattern/; # match (m can be omitted) $string =~ s/pattern/pattern/; # replace (substitute, s) $string =~ tr/pattern/pattern/; # translate Matching text if ( $name =~ m/derren/ ) if ( $name =~ /derren/ ) if ( /derren/ ) # legal but deprecated matching is the default if you omit the "m" matching is case sensitive (unless you specify otherwise) Biol Practical Biocomputing 10

11 Regular Expressions Simple patterns letters only, every letter must match /GATTACA/ delimiter // You can use other delimiters :GATTACA: : #!{ and most non whitespace characters, but some invoke special rules not \ ( ) + < [ Matching process Matches are processed left to right The first possible match (leftmost) is matched first. Once a match is found, matching stops (unless otherwise directed) The largest possible match is made (for instance if you include a *) The match is true only if the entire pattern matches Biol Practical Biocomputing 11

12 Regular Expressions Count restrictions (quantifiers) Apply to the preceding character or parenthesized group Repeated characters {n,m must occur at least n times but not more than m {n, must occur at least n times {n must occur exactly n times Shorthands (these are used much more than the forms above) * must occur zero or more times (same as {0,) + must occur or more times (same as {1,)? must occur 0 or 1 time (same as {0,1) Character classes. matches anything (except \n) [characters] matches to anything in the set of characters [^characters] matches anything NOT in the set of characters Biol Practical Biocomputing 12

13 Regular Expressions Character classes [ ] [abcd] matches any of a, b, c, or d [abcd]+ matches a run of a, b, c, or d or any length >= 1 [abcd]* matches a run of a, b, c, or d of any length, including zero [aaccggtt] matches DNA bases in upper or lower case [a-z0-9] matches lower case letters and digits [^A-Z] matches anything that is not an uppercase letter predefined character classes Note: uppercase is systematically used to mean the inverse \w [a-za-z0-9] \W [^a-za-z0-9] \d [0-9] \D [^0-9] \s [ \t\f\r\n] (includes space) \S [^\t\f\r\n] Biol Practical Biocomputing 13

14 Regular Expressions Without regular expressions, you can find things in strings using index, but it is cumbersome while ( $line = <IN> ) { ($name, $seqlen ) = split " ", $line, 2; if ( index( $name, "at1g" ) or index( $name, "at2g" ) or index( $name, "at3g" ) or index( $name, "at3g" ) or index( $name, "at3g" ) ) { print "$name\n"; while ( $line = <IN> ) { ($name, $seqlen ) = split " ", $line, 2; if ( $name =~ /at\dg/ ) { print "$name\n"; Biol Practical Biocomputing 14

15 Regular Expressions Wildcards A period matches any character # match to Arabidopsis AGI numbers if ( $name=~/at1g/ ) { print "chromosome 1: $name\n"; if ( $name=~/at.g/ ) { print "$name is in AGI format\n"; What if you want to match a period or other special character such as \ +*? Similar to strings, use a backslash to escape the special meaning Biol Practical Biocomputing 15

16 Regular Expression Escaping special characters # escaping special = ( "Arabidopsis thaliana", "A. thaliana" ); foreach $test ) { if ( $test=~/a./ ) { # test for presence of A. print "Found an abbreviation: $test\n"; if ( $test=~/a\./ ) { # correctly test for presence of A. print "Oops really found it this time: $test\n"; Biol Practical Biocomputing 16

17 Regular Expressions Wildcards Repeats * - zero or more times + - one or more times $string = "aabbbbcee"; # no d in this string if ( $string =~ /a*b*c*d*e/ ) { print "found a*b*c*d*e\n"; if ( $string =~ /a+b+c+e/ ) { print "found a+b+c+e"; Biol Practical Biocomputing 17

18 Regular Expressions Alternation match this or that /this that/ Grouping limit the alternation to just a part of the match $line =~ /frog log bog cog dog/ vs $line =~ /(fr l b c d)og/ Biol Practical Biocomputing 18

19 Regular Expressions Style # match phone numbers $phone_number =~ /\d\d\d-\d\d\d\d/ #1 $phone_number =~ /\d+-\d+/ #2 $phone_numer =~ /\(\d{3,3\)\s\d{3,3\s-\s\d{4,4/ #3 $phone_number =~ /\(\d{3,3\)\s\d{3,3\s-\s\d{4,4 \d+-\d+/ #4 Regular expressions can be very cryptic always include a comment explaining what you are testing # match phone numbers $phone_number =~ /\d\d\d-\d\d\d\d/ # $phone_number =~ /\d+-\d+/ # 1-4 $phone_numer =~ /\(\d{3,3\)\s\d{3,3\s-\s\d{4,4/ #(123) $phone_number =~ /\(\d{3,3\)\s\d{3,3\s-\s\d{4,4 \d+-\d+/ # 2 or #3 Biol Practical Biocomputing 19

20 Regular Expressions Replace (substitution, s) Change the matched expression to a new one Substitution syntax $x =~ s/ PATTERN / REPLACEMENT /; # example of substitution $name = "A. thaliana"; $name =~ s/a\./arabidopsis/; # substitute Arabidopsis for A. print "$name\n"; Biol Practical Biocomputing 20

21 Regular Expression Translation Change all the letters in PATTERN to the corresponding ones in REPLACEMENT Translation syntax $x =~ tr/ PATTERN / REPLACEMENT /; return value of translation is the number of replacements. this is useful for counting the number of occurances of something # examples of translation $name = "A. thaliana"; $name =~ tr/a-z/a-z/; print "$name\n"; # change to upper case $sequence = "ACTGACTGGTA"; print "DNA sequence is $sequence\n"; $sequence =~ tr/t/u/; print "RNA sequence is $sequence\n"; $number_of_u = $sequence =~ tr/u/u/; print "there are $number_of_u Us in this sequence\n"; Biol Practical Biocomputing 21

22 Regular Expressions Anchors tie the pattern match to the beginning (^) or end ($) of the match string greatly improves speed Modifiers modifiers follow a regular expression and effect the details of the operation i g m s case insensitive, /[aaccggtt]+/ same as /[acgt]+/i global, match or substitute across the entire string can be used to iterate over matches treat as multiple lines (^ and $ match at each line) treat as single string (allow matches that cross \n) # test regular expression modifiers $hello = "hello Hello hello"; print "original: $hello\n"; $hello =~ s/hello/hi/g; print "final: $hello\n"; $hello = "hello Hello hello"; print "original: $hello\n"; $hello =~ s/hello/hi/ig; print "final: $hello\n"; Biol Practical Biocomputing 22

23 Regular Expressions Dynamic matching Regular expression patterns can be Perl variables $pattern = '234'; $text = '12345'; print "yes!\n" if $text =~ /$pattern/; Biol Practical Biocomputing 23

24 Regular Expressions Extracting the value of a match Perl Special Variables String matching $& the string matched by the last pattern match (not counting exited blocks) $` the string preceding the last pattern match $' the string following the last pattern match Biol Practical Biocomputing 24

25 Regular Expressions Regions surrounding the match $` string before match $& matching string $' string after match $string = "To be, or not to be, that is the question, eh?"; print "\nstring:$string\n"; $n = 0; while ( $string =~ /(^ )\w\w( $)/g ) { # what does this do? include comment $n++; print "match $n\n before:$`:\n match:$&:\n after:$':\n\n"; Biol Practical Biocomputing 25

26 Regular Expressions Extracting (capturing) the value of a regular expression match parentheses meaning overloaded with grouping parentheses indicate text to be saved $line =~ /name:\s*/; $line =~ /name:\s*[^ ]+/ ; $line =~ /name:\s*([^ ]+)/ ; where is the match saved? special variables: $1, $2, $3 $name = $1; or ($name) = $line =~ /name:\s*([^ ]+)/ multiple matches # matches name: # matches name: <stuff> # saves text following "name:" ( $first, $last ) = $line =~ /surname:\s*([^ ]+)\s+first name:\s*([^ ]+)/ $1 $2 Biol Practical Biocomputing 26

27 Regular Expressions in an array or list context, the match operator returns (captures) the parts of the string that match parentheses can be nested #!/usr/bin/perl = qw( dogs ddogs cat cats log clog flogging ); foreach $word ) { if ( ($inner,$outer) = $word =~ /(fr b d (f c)?l)og/ ) { $inner = " " unless $inner; $outer = " " unless $outer; print "$word inner:$inner outer:$outer\n"; else { print "$word did not match\n"; dogs inner:d outer: ddogs inner:d outer: cat did not match cats did not match log inner:l outer: clog inner:cl outer:c flogging inner:fl outer:f Biol Practical Biocomputing 27

28 Split vs Regular Expression If regex does not match, no values are returned Very sensitive to format changes Very sensitive to missing letters, case differences, columns Id:At1G10000 Location:1,1000 GC:0.45 Id:At1G10100 location:1001,2000 GC:0.46 Id:At1G10200 Location:3001,4000 GC:0.52 The following regex is wrong, why? While ( $line = <> ) { ($id, $loc, $gc ) = $line =~ /Id:(\w+) Location:(\d+,\d+) GC:(\d+)/; No match for line two and three, all values undefined Biol Practical Biocomputing 28

29 Split vs Regular Expression Split is often more robust for column oriented formats Id:At1G10000 Location:1,1000 GC:0.45 Id:At1G10100 location:1001,2000 GC:0.46 Id:At1G10200 Location:3001,4000 GC:0.52 While ( $line = <> ) = split, $line; foreach $f ) { ($tag, $value ) = split :, $f; $info{$tag = $value; Biol Practical Biocomputing 29

30 Special Variables Predefined Variables full list: Special variables are variables predefined by the interpreter. STDIN predefined filehandle for standard input STDERR predefined filehandle for standard error STDOUT predefined filehandle for standard output $_ default input/pattern search space $. current line number in the last filehandle read $/ input record separator, default is \n $\ output record separator (prints at end of print, not between terms) $, output field separator (prints between terms) $# default output format for numbers $$ process number of the process running the script $0 name of the Perl script being an array containing the command line arguments intended for the script ARGV special filehandle that iterates over command line filenames Used in the null input operation <> $ARGV the name of the current file when reading from <ARGV> or <> %ENV has containing the current environment. Environment is the system symbols on your computer (OS specific) Biol Practical Biocomputing 30

31 Special Variables $_ default input/pattern search space Used in many contexts as a default value, among others default variable for input <> operator default target for print default target for string matching default target for chomp and chop Makes code brief, but Risky because many operations change it, and hard to understand while ( <> ) { print; while ( $_ = <> ) { print $_; while ( $line = <> ) { print $line; # $_ is implicit # means the same # much less likely to go wrong Biol Practical Biocomputing 31

32 Special Variables default input/pattern search space, more examples while ( <> ) { chomp; if ( /^>/ ) { print; # beginning of FASTA sequence while ( $_ = <> ) { chomp $_; # means the same if ( $_ =~ /^>/ ) { print $_; while ( $line = <> ) { chomp $line; # preferred method, easier to understand # less susceptible to side effects if ( $line =~ /^>/ ) { print $line; Biol Practical Biocomputing 32

33 Special Variables Command line The line of text you type when you run a program Command line is used to specify "switches" and files % myprogram.pl file1.txt file2.txt % perl myprogram.pl file1.txt file2.txt % myprogram.pl v n100 file1.txt is used to see what is on the command line don t process by hand, use Getopt package # command line print "command line parameters\n"; $count = 0; foreach $param ) { print "parameter $count: $ARGV[$count]\n"; $count++; Biol Practical Biocomputing 33

34 Special Variables Command line $ARGV tells the current file when reading from <STDIN> ( <> ) # files on command line #initialize filename to be blank, number of files to be zero $file = ""; $file_count = 0; while ( <> ) { if ( $ARGV ne $file ) { # if the current file is different than the one in the last line # print out the file name $file_count++; $file = $ARGV; print "file $file_count:$file:\n"; pro:~/perlcourse(95)% perl argv.pl split2.txt split.txt file 1:split2.txt: file 2:split.txt: Biol Practical Biocomputing 34

35 Special Variables What is this process? # Echo the name and ID of this process $script = $0; $id = $$; print "script = $script ID = $id\n"; What is my environment? Environment is a set of symbols that are known to the operating system # Echo the process environment foreach $symbol ( keys %ENV ) { print "$symbol => $ENV{ $symbol \n"; Biol Practical Biocomputing 35

36 Special Variables Use English qw( -no_match_vars ); Avoids problems with regexes Provides English equivalents for special variables See for details, e.g., $_ == $ARG $ == $LIST_SEPARATOR $$ == $PROCESS_ID $0 == $PROGRAM_NAME $; == $SUBSCRIPT_SEPARATOR Biol Practical Biocomputing 36

37 Intermediate Perl Sorting The sort function can use any function we provide to sort allows other sorts than alphabetical allows multiple key sorts Custom sorting is performed by including a function inside { between "sort" and the list being sorted, e.g., ( sort { $a cmp ) $a and $b are special variables that refer to two objects in the list being sorted (defined only within sort) You must provide a function that can be used to compare the things be sorted as pairs of objects <=> (numeric) and cmp (alphabetic) are two such functions comparison function returns -1 for $a < $b $a lt $b 0 for $a == $b $a eq $b +1 for $a > $b $a gt $b Biol Practical Biocomputing 37

38 Intermediate Perl Sorting the sort function works on a list $a and $b are predefined local variables that represent any two items in the list being sorted The sort function tells how to compare two items in the list ($a and $b) and decide which goes first sort { $a <=> $b ( 0, 12, 7,14 ); sort { $b <=> $a ( 0, 12, 7, 14 ); sort { $age[$a] <=> $age[$b] ( 0..9 ); # sorts by number small to large # sorts by number large to small # sorts by values Biol Practical Biocomputing 38

39 Intermediate Perl Sorting Bubble Sort (not a very efficient sort, O(n 2 ) ) $swapped = 1; while ( $swapped ) { $swapped = 0; foreach $i ( 1.. $#a ) { if ( $a[$i-1] > $a[$i] ) { swap( $a[$i-1], $a[$i] ); $swapped = 1; for a = qw( ) # exchange position $i-1 and $i in list Biol Practical Biocomputing 39

40 Intermediate Perl Sorting Perl uses a more efficient sort called a quicksort (or qsort) which uses O(n log n) time (bubble sort is O(n 2 ) = ( 47, 34, 8, 23, 1 = sort { $result=$a cmp $b; print "$a\t$b\t$result; $a > $b $a > $b $a > $b $a < $b no change $a < $b no change $a > $b Biol Practical Biocomputing 40

41 Intermediate Perl Sorting Sorting the indices instead of the array Useful with parallel = ( 47, 34, 8, 23, 1 = ( 0.. $#a ); $a[$index] $swapped = 1; while ( $swapped ) { $swapped = 0; foreach $i ( 1.. $#index ) { if ( $a[$index[$i-1]] > $a[$index[$i]] ) { swap( $index[$i-1], $index[$i] ); # exchange index $i-1 and $i $swapped = 1; if ( $swapped ) { print "@a\t@index\n"; Biol Practical Biocomputing 41

42 Intermediate Perl Sorting Sorting in the opposite order foreach $i ( ) { foreach $i ( sort { $a cmp ) { foreach $i ( sort { $b cmp ) { # default, means the same # opposite = qw( jane jeff, william, kejie, aditi ); print " = print " = sort { $b cmp print " reverse original list: jane jeff william kejie aditi default sort: aditi jane jeff kejie william reverse sort: william kejie jeff jane aditi Biol Practical Biocomputing 42

43 Intermediate Perl Sorting Sorting in numerical rather than alphabetical = ( 47, 34, 8, 23, 1 = sort { $a cmp # same as default = sort { $a <=> print = sort { $b <=> print "\nnumerically alphabetically: numerically ascending: numerically descending: Biol Practical Biocomputing 43

44 Intermediate Perl Sorting Sorting hashes %height = ( jane => 165, jeff => 188, william => 177, aditi => 160 ); # sort by name print "\nby name\n"; foreach $person ( sort keys %height ) { print "$person: $height{ $person \n"; # sort by height print "\nby height\n"; by name aditi: 160 jane: 165 jeff: 188 william: 177 by height aditi: 160 jane: 165 william: 177 jeff: 188 foreach $person ( sort { $height{$a <=> $height{$b keys %height ) { print "$person: $height{ $person \n"; Biol Practical Biocomputing 44

45 Intermediate Perl Sorting Multiple key sorting sorting first by one thing, then another, for instance first by age, then by weight Use (or) to separate tests, the second is applied only if the first is equal %age = ( albert => 18, annette => 27, armand => 21, alice => 18, anwar => 42 ); %wgt = ( albert => 185, annette => 275, armand => 121, alice => 108, anwar => 108 ); first test: age alice albert armand annette anwar second test: weight foreach $name (sort { $age{$a <=> $age{$b $wgt{$a <=> $wgt{$b keys %age ) { print "$name $age{$name $wgt{$name\n"; Biol Practical Biocomputing 45

46 Intermediate Perl Sorting Multiple keys using a sort function %age = ( albert => 18, annette => 27, armand => 21, alice => 18, anwar => 42 ); %wgt = ( albert => 185, annette => 275, armand => 121, alice => 108, anwar => 108 ); alice albert armand annette anwar sub byageandwgt { $age{$a <=> $age{$b $wgt{$a <=> $wgt{$b foreach $name (sort byageandwgt keys %age ) { print "$name $age{$name $wgt{$name\n"; Biol Practical Biocomputing 46

47 Intermediate Perl Sorting Rolling your own sort function Function must return -1 if $a < $b 0 if $a == $b 1 if $a > $b # uses hash from previous example as data # sort function: sorts annette to the first position, other # names alphabetically sub annettefirst { if ( $a eq 'annette' ) {return -1; elsif ( $b eq 'annette' ) { return 1; else { return $a cmp $b; foreach $name (sort annettefirst keys %age ) { annette albert alice anwar armand print "$name $age{$name $wgt{$name\n"; Biol Practical Biocomputing 47

48 Intermediate Perl Sorting Rolling your own sort function # uses hash from previous example as data # sort function: sorts by name backwards sub backwards { my $a_backwards = reverse( $a ); my $b_backwards = reverse( $b ); return $a_backwards cmp $b_backwards armand alice annette anwar albert foreach $name (sort backwards keys %age ) { print "$name $age{$name $wgt{$name\n"; Biol Practical Biocomputing 48

49 Intermediate Perl Sorting Example Sort the following sequences by length and %GC aay ACGATGAGCTAGCATTCGATGCTACATTGTGTCCA caa TATATATATATATTATTTTTTATTATATTAGCGCGTTTTT dbd TTAGCGTACTGCTTGACTGACTGTATTGTACATG eef TGTATTCGCGCCATATCCGATTGCGACTAGCTACCC rpo CACATCATCGAGGGGCTATCGATGGCTGATGCGCA 5 sequences converted to hash form Length and % GC calculated for 5 sequences gene length % GC dbd TTAGCGTACTGCTTGACTGACTGTATTGTACATG aay ACGATGAGCTAGCATTCGATGCTACATTGTGTCCA rpo CACATCATCGAGGGGCTATCGATGGCTGATGCGCA eef TGTATTCGCGCCATATCCGATTGCGACTAGCTACCC caa TATATATATATATTATTTTTTATTATATTAGCGCGTTTTT Biol Practical Biocomputing 49

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

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

(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

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

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

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

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

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

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

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

Week January 27 January. From last week Arrays. Reading for this week Hashes. Files. 24 H: Hour 4 PP Ch 6:29-34, Ch7:51-52

Week January 27 January. From last week Arrays. Reading for this week Hashes. Files. 24 H: Hour 4 PP Ch 6:29-34, Ch7:51-52 Week 3 23 January 27 January From last week Arrays 24 H: Hour 4 PP Ch 6:29-34, Ch7:51-52 Reading for this week Hashes 24 H: Hour 7 PP Ch 6:34-37 Files 24 H: Hour 5 PP Ch 19: 163-169 Biol 59500-033 - Practical

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

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

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. 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

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

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

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

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

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

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs Summer 2010 Department of Computer Science and Engineering York University Toronto June 29, 2010 1 / 36 Table of contents 1 2 3 4 2 / 36 Our goal Our goal is to see how we can use Unix as a tool for developing

More information

Title:[ Variables Comparison Operators If Else Statements ]

Title:[ Variables Comparison Operators If Else Statements ] [Color Codes] Environmental Variables: PATH What is path? PATH=$PATH:/MyFolder/YourStuff?Scripts ENV HOME PWD SHELL PS1 EDITOR Showing default text editor #!/bin/bash a=375 hello=$a #No space permitted

More information

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc. Appendix B WORKSHOP SYS-ED/ Computer Education Techniques, Inc. 1 Scalar Variables 1. Write a Perl program that reads in a number, multiplies it by 2, and prints the result. 2. Write a Perl program that

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

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

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

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

Introduction to Perl programmation & one line of Perl program. BOCS Stéphanie DROC Gaëtan ARGOUT Xavier

Introduction to Perl programmation & one line of Perl program. BOCS Stéphanie DROC Gaëtan ARGOUT Xavier Introduction to Perl programmation & one line of Perl program BOCS Stéphanie DROC Gaëtan ARGOUT Xavier Introduction What is Perl? PERL (Practical Extraction and Report Language) created in 1986 by Larry

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

COMS 3101 Programming Languages: Perl. Lecture 3

COMS 3101 Programming Languages: Perl. Lecture 3 COMS 3101 Programming Languages: Perl Lecture 3 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Array / Hash manipulation (continued) Pattern Matching

More information

IT441. Network Services Administration. Perl: File Handles

IT441. Network Services Administration. Perl: File Handles IT441 Network Services Administration Perl: File Handles Comment Blocks Perl normally treats lines beginning with a # as a comment. Get in the habit of including comments with your code. Put a comment

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

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

Control Structures. Important Semantic Difference

Control Structures. Important Semantic Difference Control Structures Important Semantic Difference In all of these loops we are going to discuss, the braces are ALWAYS REQUIRED. Even if your loop/block only has one statement, you must include the braces.

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

CMSC 330: Organization of Programming Languages. Ruby Regular Expressions

CMSC 330: Organization of Programming Languages. Ruby Regular Expressions CMSC 330: Organization of Programming Languages Ruby Regular Expressions 1 String Processing in Ruby Earlier, we motivated scripting languages using a popular application of them: string processing The

More information

Learning Perl 6. brian d foy, Version 0.6, Nordic Perl Workshop 2007

Learning Perl 6. brian d foy, Version 0.6, Nordic Perl Workshop 2007 Learning Perl 6 brian d foy, Version 0.6, Nordic Perl Workshop 2007 for the purposes of this tutorial Perl 5 never existed Don t really do this $ ln -s /usr/local/bin/pugs /usr/bin/perl

More information

Beginning Perl. Third Edition. Apress. JAMES LEE with SIMON COZENS

Beginning Perl. Third Edition. Apress. JAMES LEE with SIMON COZENS Beginning Perl Third Edition JAMES LEE with SIMON COZENS Apress About the Author... About the Technical Reviewers Acknowledgements Suitrod yetion «. xvi xvii xviii «xix. Chapter 1: First Steps in Perl..

More information

UNIX Shell Programming

UNIX Shell Programming $!... 5:13 $$ and $!... 5:13.profile File... 7:4 /etc/bashrc... 10:13 /etc/profile... 10:12 /etc/profile File... 7:5 ~/.bash_login... 10:15 ~/.bash_logout... 10:18 ~/.bash_profile... 10:14 ~/.bashrc...

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Perl for Biologists. Regular Expressions. Session 7. Jon Zhang. April 23, Session 7: Regular Expressions CBSU Perl for Biologists 1.

Perl for Biologists. Regular Expressions. Session 7. Jon Zhang. April 23, Session 7: Regular Expressions CBSU Perl for Biologists 1. Perl for Biologists Session 7 April 23, 2014 Regular Expressions Jon Zhang Session 7: Regular Expressions CBSU Perl for Biologists 1.1 1 Review of Session 6 Each program has three default input/output

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

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

Programming Languages and Uses in Bioinformatics

Programming Languages and Uses in Bioinformatics Programming in Perl Programming Languages and Uses in Bioinformatics Perl, Python Pros: reformatting data files reading, writing and parsing files building web pages and database access building work flow

More information

Regular Expressions. Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland

Regular Expressions. Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland Regular Expressions Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland November 11 th, 2015 Regular expressions provide a flexible way

More information

Module 8 Pipes, Redirection and REGEX

Module 8 Pipes, Redirection and REGEX Module 8 Pipes, Redirection and REGEX Exam Objective 3.2 Searching and Extracting Data from Files Objective Summary Piping and redirection Partial POSIX Command Line and Redirection Command Line Pipes

More information

PERL Bioinformatics. Nicholas E. Navin, Ph.D. Department of Genetics Department of Bioinformatics. TA: Dr. Yong Wang

PERL Bioinformatics. Nicholas E. Navin, Ph.D. Department of Genetics Department of Bioinformatics. TA: Dr. Yong Wang PERL Bioinformatics Nicholas E. Navin, Ph.D. Department of Genetics Department of Bioinformatics TA: Dr. Yong Wang UNIX Background and History PERL Practical Extraction and Reporting Language Developed

More information

IT441. Subroutines. (a.k.a., Functions, Methods, etc.) DRAFT. Network Services Administration

IT441. Subroutines. (a.k.a., Functions, Methods, etc.) DRAFT. Network Services Administration IT441 Network Services Administration Subroutines DRAFT (a.k.a., Functions, Methods, etc.) Organizing Code We have recently discussed the topic of organizing data (i.e., arrays and hashes) in order to

More information

On The First Steps. Chapter 1. In This Chapter

On The First Steps. Chapter 1. In This Chapter Chapter 1 On The First Steps In This Chapter 1.1 The First Perl Program........................................ 2 1.2 Using Scalar Variables........................................ 4 1.3 Declaring Variables:

More information

Unleashing the Shell Hands-On UNIX System Administration DeCal Week 6 28 February 2011

Unleashing the Shell Hands-On UNIX System Administration DeCal Week 6 28 February 2011 Unleashing the Shell Hands-On UNIX System Administration DeCal Week 6 28 February 2011 Last time Compiling software and the three-step procedure (./configure && make && make install). Dependency hell and

More information

Bioinformatics. Computational Methods II: Sequence Analysis with Perl. George Bell WIBR Biocomputing Group

Bioinformatics. Computational Methods II: Sequence Analysis with Perl. George Bell WIBR Biocomputing Group Bioinformatics Computational Methods II: Sequence Analysis with Perl George Bell WIBR Biocomputing Group Sequence Analysis with Perl Introduction Input/output Variables Functions Control structures Arrays

More information

IT441. Network Services Administration. Data Structures: Arrays

IT441. Network Services Administration. Data Structures: Arrays IT441 Network Services Administration Data Structures: Arrays Data Types Remember there are three basic data types in Perl o Numeric o String o Boolean (Logical) I differentiate between data types and

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

Regular Expressions: The Power of Perl

Regular Expressions: The Power of Perl Regular Expressions: The Power of Perl 1. What is a regular expression (regex)? - it is a description for a group of characters you want to search for in a string, a file, a website, etc... - think of

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

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

Pod::Usage, pod2usage() - print a usage message from embedded pod documentation

Pod::Usage, pod2usage() - print a usage message from embedded pod documentation NAME Pod::Usage, pod2usage() - print a usage message from embedded pod documentation SYNOPSIS use Pod::Usage my $message_text = "This text precedes the usage message."; my $exit_status = 2; ## The exit

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

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

CSCI 4152/6509 Natural Language Processing Lecture 6: Regular Expressions; Text Processing in Perl

CSCI 4152/6509 Natural Language Processing Lecture 6: Regular Expressions; Text Processing in Perl Lecture 6 p.1 Faculty of Computer Science, Dalhousie University CSCI 4152/6509 Natural Language Processing Lecture 6: Regular Expressions; Text Processing in Perl 18-Jan-2019 Location: LSC Psychology P5260

More information

Programming introduction part I:

Programming introduction part I: Programming introduction part I: Perl, Unix/Linux and using the BlueHive cluster Bio472- Spring 2014 Amanda Larracuente Text editor Syntax coloring Recognize several languages Line numbers Free! Mac/Windows

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

AC109/AT109 UNIX & SHELL PROGRAMMING DEC 2014

AC109/AT109 UNIX & SHELL PROGRAMMING DEC 2014 Q.2 a. Explain the principal components: Kernel and Shell, of the UNIX operating system. Refer Page No. 22 from Textbook b. Explain absolute and relative pathnames with the help of examples. Refer Page

More information

Perl Tutorial. Diana Inkpen. School of Information Technology and Engineering University of Ottawa. CSI 5180, Fall 2004

Perl Tutorial. Diana Inkpen. School of Information Technology and Engineering University of Ottawa. CSI 5180, Fall 2004 Perl Tutorial Diana Inkpen School of Information Technology and Engineering University of Ottawa CSI 5180, Fall 2004 1 What is Perl Practical Extraction and Report Language. Created, implemented, maintained

More information

CS 105 Perl: Perl subroutines and Disciplined Perl

CS 105 Perl: Perl subroutines and Disciplined Perl CS 105 Perl: Perl subroutines and Disciplined Perl Nathan Clement! February 3, 2014 Agenda We will cover Perl scoping, subroutines (user- defined functions) and then we continue on to Perl s features for

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

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

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

This page covers the very basics of understanding, creating and using regular expressions ('regexes') in Perl.

This page covers the very basics of understanding, creating and using regular expressions ('regexes') in Perl. NAME DESCRIPTION perlrequick - Perl regular expressions quick start Perl version 5.16.2 documentation - perlrequick This page covers the very basics of understanding, creating and using regular expressions

More information

CS Unix Tools. Fall 2010 Lecture 5. Hussam Abu-Libdeh based on slides by David Slater. September 17, 2010

CS Unix Tools. Fall 2010 Lecture 5. Hussam Abu-Libdeh based on slides by David Slater. September 17, 2010 Fall 2010 Lecture 5 Hussam Abu-Libdeh based on slides by David Slater September 17, 2010 Reasons to use Unix Reason #42 to use Unix: Wizardry Mastery of Unix makes you a wizard need proof? here is the

More information

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell. Command Interpreters A command interpreter is a program that executes other programs. Aim: allow users to execute the commands provided on a computer system. Command interpreters come in two flavours:

More information

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash CS 25200: Systems Programming Lecture 10: Shell Scripting in Bash Dr. Jef Turkstra 2018 Dr. Jeffrey A. Turkstra 1 Lecture 10 Getting started with Bash Data types Reading and writing Control loops Decision

More information

Regular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl)

Regular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl) Regular Expressions Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl) JavaScript started supporting regular expressions in

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

By default, optional warnings are disabled, so any legacy code that doesn't attempt to control the warnings will work unchanged.

By default, optional warnings are disabled, so any legacy code that doesn't attempt to control the warnings will work unchanged. SYNOPSIS use warnings; no warnings; use warnings "all"; no warnings "all"; use warnings::register; if (warnings::enabled()) warnings::warn("some warning"); if (warnings::enabled("void")) warnings::warn("void",

More information

Perl Primer An Introduction to Perl for C++ Programmers by Frank McCown and Tim Baird Harding University

Perl Primer An Introduction to Perl for C++ Programmers by Frank McCown and Tim Baird Harding University Perl Primer An Introduction to Perl for C++ Programmers by Frank McCown and Tim Baird Harding University PERL is the Practical Extraction and Report Language (or Pathologically Eclectic Rubbish Lister)

More information

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1 Shell Scripting Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 If we have a set of commands that we want to run on a regular basis, we could write a script A script acts as a Linux command,

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

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

While Statement Examples. While Statement (35.15) Until Statement (35.15) Until Statement Example

While Statement Examples. While Statement (35.15) Until Statement (35.15) Until Statement Example While Statement (35.15) General form. The commands in the loop are performed while the condition is true. while condition one-or-more-commands While Statement Examples # process commands until a stop is

More information

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

A Field Guide To The Perl Command Line. Andy Lester

A Field Guide To The Perl Command Line. Andy Lester A Field Guide To The Perl Command Line Andy Lester andy@petdance.com http://petdance.com/perl/ Where we're going Command-line == super lazy The magic filehandle The -e switch -p, -n: Implicit looping -a,

More information

Perl Primer by Frank McCown and Tim Baird

Perl Primer by Frank McCown and Tim Baird Page 1 of 13 Perl Primer by Frank McCown and Tim Baird PERL is the Practical Extraction and Report Language (or Pathologically Eclectic Rubbish Lister) Developed by Larry Wall who is still the chief architect.

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

perl -MO=Deparse[,-d][,-fFILE][,-p][,-q][,-l] [,-sletters][,-xlevel] prog.pl

perl -MO=Deparse[,-d][,-fFILE][,-p][,-q][,-l] [,-sletters][,-xlevel] prog.pl NAME SYNOPSIS DESCRIPTION OPTIONS B::Deparse - Perl compiler backend to produce perl code perl -MO=Deparse[,-d][,-fFILE][,-p][,-q][,-l] [,-sletters][,-xlevel] prog.pl B::Deparse is a backend module for

More information

The Power of Perl. Perl. Perl. Change all gopher to World Wide Web in a single command

The Power of Perl. Perl. Perl. Change all gopher to World Wide Web in a single command The Power of Perl Perl Change all gopher to World Wide Web in a single command perl -e s/gopher/world Wide Web/gi -p -i.bak *.html Perl can be used as a command Or like an interpreter UVic SEng 265 Daniel

More information

COMP 4/6262: Programming UNIX

COMP 4/6262: Programming UNIX COMP 4/6262: Programming UNIX Lecture 12 shells, shell programming: passing arguments, if, debug March 13, 2006 Outline shells shell programming passing arguments (KW Ch.7) exit status if (KW Ch.8) test

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

Common File System Commands

Common File System Commands Common File System Commands ls! List names of all files in current directory ls filenames! List only the named files ls -t! List in time order, most recent first ls -l! Long listing, more information.

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

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

Perl Regular Expressions. Perl Patterns. Character Class Shortcuts. Examples of Perl Patterns

Perl Regular Expressions. Perl Patterns. Character Class Shortcuts. Examples of Perl Patterns Perl Regular Expressions Unlike most programming languages, Perl has builtin support for matching strings using regular expressions called patterns, which are similar to the regular expressions used in

More information

Perl for Biologists. Session 8. April 30, Practical examples. (/home/jarekp/perl_08) Jon Zhang

Perl for Biologists. Session 8. April 30, Practical examples. (/home/jarekp/perl_08) Jon Zhang Perl for Biologists Session 8 April 30, 2014 Practical examples (/home/jarekp/perl_08) Jon Zhang Session 8: Examples CBSU Perl for Biologists 1.1 1 Review of Session 7 Regular expression: a specific pattern

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

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

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

Computational Theory MAT542 (Computational Methods in Genomics) - Part 2 & 3 -

Computational Theory MAT542 (Computational Methods in Genomics) - Part 2 & 3 - Computational Theory MAT542 (Computational Methods in Genomics) - Part 2 & 3 - Benjamin King Mount Desert Island Biological Laboratory bking@mdibl.org Overview of 4 Lectures Introduction to Computation

More information

Introduc)on to Unix and Perl programming

Introduc)on to Unix and Perl programming CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS Department of Systems Biology Technical University of Denmark Introduc)on to Unix and Perl programming EDITA KAROSIENE PhD student edita@cbs.dtu.dk www.cbs.dtu.dk

More information

Iterative Languages. Scoping

Iterative Languages. Scoping Iterative Languages Scoping Sample Languages C: static-scoping Perl: static and dynamic-scoping (use to be only dynamic scoping) Both gcc (to run C programs), and perl (to run Perl programs) are installed

More information

Perl for Biologists. Session 9 April 29, Subroutines and functions. Jaroslaw Pillardy

Perl for Biologists. Session 9 April 29, Subroutines and functions. Jaroslaw Pillardy Perl for Biologists Session 9 April 29, 2015 Subroutines and functions Jaroslaw Pillardy Perl for Biologists 1.2 1 Suggestions Welcomed! There are three more sessions devoted to practical examples They

More information