Lec8Handouts - CS2044 - Advanced Unix Tools Spring 2009...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2044 - Advanced Unix Tools Spring 2009 Lecture 8 David Slater dms236 at cornell.edu March 7, 2009 David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Organization Homework 2 Due Monday March 8th Hopefully You Started Early! Turn In Code That Works! Follow Directions Homework 3 Will be on the website by tomorrow night Homework 3 Due Next Sunday at 11:59PM David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 2
Review / Clarification /abc(?=def)/ matches abc only if it is directly followed by def In for loops we can use the range operator . . for $x (0 . . 10) { print $x; } David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
You can specify the delimiter for regular expression by using the m option /http:\/\/www\.cam\.cornell\.edu\/~slater\/cs2044\/index\.html/ Becomes m#http://www\.cam\.cornell\.edu/~slater/cs2044/index\.html# And you can escape everything by using \Q followed by \E m#\Qhttp://www.cam.cornell.edu/~slater/cs2044/index.html\E# David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 4
The Perl Motto ”There’s more than one way to do it” The following is just fine Print $x if ( $x eq /someregexp/); (Read Right to Left) David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Arrays Perl can do standard arrays and associative arrays (dictionaries). We’ll talk about associative arrays later. An array variable is just like a scalar variable except it starts with @: @names = ("David", "James", "Joan", "Sarah"); print "The elements of names are @names\n"; print "The first element is $names[0] \n"; print "There are ", scalar(@names)," elements in the array\n"; Prints: The elements of @names are David James Joan Sarah The first element is David There are 4 elements in the array David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 6
Arrays When referring to more than one variable use @array When referring to a single element use $array[i] $array would refer to a scalar variable called array. @array[i,j,k] to refer to multiple elements @array[i. .j] to refer to a range of elements $#array to refer to the last index $scalar = @array will set $scalar to the length of @array. David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Looping over elements in an array is easy for $x (@array) { print "$x \n; } foreach $x (@array) { print "$x \n; } Both are equivalent. David Slater dms236 at cornell.edu
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

Lec8Handouts - CS2044 - Advanced Unix Tools Spring 2009...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online