35 Pages

Perl4-2

Course: COMP 519, Fall 2009
School: East Los Angeles College
Rating:
 
 
 
 
 

Word Count: 3329

Document Preview

Web COMP519: Programming Autumn 2008 Perl Tutorial: Beyond the Basics Keyboard Input and file handling Control structures Conditionals String Matching Substitution and Translation Split Associative arrays Subroutines References Keyboard Input #!/usr/local/bin/perl # basic08.pl COMP519 print "Please input the circles radius: "; $radius = <STDIN>; $area = 3.14159265 *...

Register Now

Unformatted Document Excerpt

Coursehero >> California >> East Los Angeles College >> COMP 519

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Web COMP519: Programming Autumn 2008 Perl Tutorial: Beyond the Basics Keyboard Input and file handling Control structures Conditionals String Matching Substitution and Translation Split Associative arrays Subroutines References Keyboard Input #!/usr/local/bin/perl # basic08.pl COMP519 print "Please input the circles radius: "; $radius = <STDIN>; $area = 3.14159265 * $radius * $radius; print "The area is: $area \n"; STDIN is the predefined filehandle for standard input, the keyboard. The line input operator is specified with <filehandle> $new = <STDIN>; bash-2.05b$ ./ basic08.pl Please input the circle's radius: 100 The area is: 31415.9265 If the input is a string value, we often want to trim off the trailing newline, so we use the ubiquitous chomp function. chomp($new = <STDIN>); Equivalent to $new = <STDIN>; chomp($new); File Handling #!/usr/local/bin/perl # basic09. pl COMP 519 # Program to open the password file, # read it in, print it, and close it again. $file = 'password.dat'; #Name the file open(INFO, $file); #Open the file @lines = <INFO>; #Read it into an array close(INFO); #Close the file print @lines; #Print the array Define filename $file open this file for input (reading) using filehandle INFO (or some other name) read the entire file into the array in one go using @lines = <INFO>; close that file Can do even more: open(INFO, open(INFO, open(INFO, open(INFO, $file); # Open for input, i.e. reading ">$file"); # Open for new output, i.e. writing ">>$file"); # Open for appending "<$file"); # also for reading print the array (this will print the entire array in one go) Can use print with an extra parameter, e.g. print INFO "This line goes to the file.\n"; Example password.dat: password1 password2 password3 password4 password5 ... ... ... #!/usr/local/bin/perl # basic09. pl COMP 519 # Program to open the password file, # read it in, print it, and close it again. $file = 'password.dat'; #Name the file open(INFO, $file); #Open the file @lines = <INFO>; #Read it into an array close(INFO); #Close the file print @lines; #Print the array bash-2.05b$ perl basic09.pl password1 password2 password3 password4 password5 ... ... ... foreach-Statement Can go through each line of an array or other list-like structure (such as lines in a file) #!/usr/local/bin/perl # basic10.pl COMP519 @food = ("apples", "pears", "eels"); foreach $morsel (@food) # Visit each item in turn and call it # $morsel { print "$morsel \n"; # Print the item print "Yum yum\n"; # That was nice } bash-2.05b$ perl basic10.pl apples Yum yum pears Yum yum eels Yum yum Testing In Perl any non-zero number and non-empty string is counted as true. The number zero, zero by itself in a string, and the empty string are counted as false. Here are some tests on numbers and strings. $a == $b $a != $b $a eq $b $a ne $b # Is $a numerically equal to $b? # Beware: Don't use the = operator. # Is $a numerically unequal to $b? # Is $a string-equal to $b? # Is $a string-unequal to $b? You can also use logical and, or and not: ($a && $b) ($a || $b) !($a) # Is $a and $b true? # Is either $a or $b true? # is $a false? Control Operations Loop Statements for #!/usr/local/bin/perl # basic11.pl COMP519 for ($i = 0; $i < 10; ++$i) # Start with $i = 1 # Do it while $i < 10 # Increment $i before repeating { print "iteration $i\n"; } Perl has loop statements that mimic those of C and Java while #!/usr/local/bin/perl # basic12.pl COMP519 print "Password?\n; # Ask for input $a = <STDIN>; # Get input chomp $a; # Remove the newline at end while ($a ne "fred") #While input is wrong.. { print "sorry. Again?\n"; # Ask again $a = <STDIN>; # Get input again chomp $a; # Chop off newline again } do-until #!/usr/local/bin/perl # basic13.pl COMP519 do { print "Password? "; #Ask for input $a = <STDIN>; #Get input chomp $a; # Chop off newline } until($a eq "fred") # Redo until correct input Examples for bash-2.05b$ perl basic11.pl iteration 0 iteration 1 iteration 2 iteration 3 iteration 4 iteration 5 iteration 6 iteration 7 iteration 8 iteration 9 while bash-2.05b$ perl basic12.pl Password? wew sorry. Again? wqqw sorry. Again? fred do-until bash-2.05b$ perl basic13.pl Password? werfwe Password? qfvcc Password? qcqc Password? fred Conditionals Of course Perl also allows if/then/else statements. if ($a) { print "The string is not empty\n"; } else { print "The string is empty\n"; } if (!$a) # The ! is the not operator { print "The string is empty\n"; } elsif (length($a) == 1) # If above fails, try this { print "The string has one character\n"; } elsif (length($a) == 2) # If that fails, # try this { print "The string has two characters\n"; } else #Now, everything has failed { print "The string has lots of characters\n"; } Remember that an empty string is FALSE. Also, FALSE" if $a is the string 0 or 0. Notice, the elsif does have an "e" missing. Strings and text processing One of the strengths of Perl is its capabilities for processing strings (and its speed in doing so). Perl has many built-in functions for manipulating strings, some of which have been mentioned earlier, like (assuming that $str is a variable that holds a string) $s = uc ($str); # Convert a string to uppercase $l = length($str); # Get the length of a string The real power comes from Perls regular expression engine used for matching, substituting, and otherwise manipulating strings. Regular expressions exist in other languages (including Java, JavaScript, and PHP), but Perl has this built into the standard syntax of the language (where is others its accessed through other libraries). Regular Expressions A regular expression is a template that matches, or doesnt match, a given string. $sentence =~ /the/ gives TRUE if the appears in $sentence The RE is slashed / /, matching occurs after the =~ operator (which is called the binding operator). So, if $sentence = "The quick brown fox"; then the above match will be FALSE. The RE is case sensitive. So, $sentence =~ /the/ is FALSE because the does not appear in $sentence The operator !~ is used for spotting a non-match. Example #!/usr/local/bin/perl # basic14.pl COMP519 $sentence = "The quick brown fox"; $a = ($sentence =~ /the/) ; $b= ($sentence !~ /the/); print "Output gives $a and $b\n"; bash-2.05b$ perl basic14.pl Output gives and 1 Using the $_ Special Variable Can use the Regular Expression as a conditional, e.g. if ($sentence =~ /under/) { print "We're talking about rugby\n"; } It works if we had either of $sentence = "Up and under"; $sentence = "Best in Sunderland"; By assigning the sentence to the special variable $_ first, we can avoid using the match and non-match operators. if (/under/) { print "We're talking about rugby\n"; } Note: As mentioned previously, the $_ variable is the default variable for many Perl operations and tends to be used very heavily. More on REs The creation of REs can be something of an art form. . ^ $ * + ? # Any single character except a newline # The beginning of the line or string # The end of the line or string # Zero or more of the last character # One or more of the last character # Zero or one of the last character Here are some special RE characters and their meaning. Some example matches: t.e ^f ^ftp e$ tle$ und* .* ^$ # t followed by anything followed by e. This will match tre, tle but not te, tale # f at the beginning of a line # ftp at the beginning of a line # e at the end of a line # tle at the end of a line # un followed by zero or more d characters. This will match un, und, undd, unddd, # Any string without a newline. This is because the . matches anything except # a newline and the * means zero or more of these. # A line with nothing in it. Remember that the RE should be enclosed in /.../ slashes to be used. Even more on REs Can use [] to match any one of the characters inside them. [qjk] [^qjk] [a-z] [^a-z] [a-zA-Z] [a-z]+ # Either q or j or k # Neither q nor j nor k # Anything from a to z inclusive # No lower case letters # Any letter # Any non-zero sequence of lower case letters a - indicates "between a ^ means "not": Can use | for an "or" and (...) for grouping things together. jelly|cream # Either jelly or cream (eg|le)gs # Either eggs or legs (da)+ # Either da or dada or dadada or... Still More on REs Can use some more special characters, and escape sequences \n \t \w \W \d \D \s \S \b \B # A newline # A tab # Any alphanumeric (word) character. # The same as [a-zA-Z0-9_] # Any non-word character. # The same as [^a-zA-Z0-9_] # Any digit. The same as [0-9] # Any non-digit. The same as [^0-9] # Any whitespace character: space, # tab, newline, etc # Any non-whitespace character # A word boundary, outside [] only # No word boundary \| \[ \) \* \^ \/ \\ # Vertical bar # An open square bracket # A closing parenthesis # An asterisk # A carat symbol # A slash # A backslash * Find more on REs! Some Example REs It's probably best to build up your use of regular expressions slowly. Here are a few examples. # Either "0" or "1" # A division by zero: "/0" # A division by zero with a space: "/ 0" # A division by zero with a whitespace: # "/ 0" where the space may be a tab etc. \/ *0 # A division by zero with possibly some # spaces: "/0" or "/ 0" or "/ 0" etc. \/\s*0 # A division by zero with possibly some whitespace. \/\s*0\.0* # As the previous one, but with decimal # point and maybe some 0s after it. Accepts # "/0." and "/0.0" and "/0.00" etc and # "/ 0." and "/ 0.0" and "/ 0.00" etc. [01] \/0 \/ 0 \/\s0 Remember that to use them for matching they should be put in /.../ slashes. Substitution As well as identifying REs, can make substitutions using function s based on those matches. $sentence =~ s/london/London/; This replaces the first occurrence of london by London in the string $sentence s/london/London/; This does the same thing with the $_ variable. This makes a global substitution (in the $_ variable) by using the g option (for global case") after the last slash. s/london/London/g; This RE below can replace occurrences of lOndon, lonDON, LoNDoN and so on s/[Ll][Oo][Nn][Dd][Oo][Nn]/London/g but an easier way is to use the i option (for "ignore case"). s/london/London/gi This will make a global substitution ignoring case. The i option is also used in the basic /.../ regular expression match. Example #!/usr/local/bin/perl # basic15.pl COMP519 $_ = "I love london, but not london or LoNdoN"; $a = s/london/London/; # $a gives number of changes in $_ but # the changes are made to $_ print "$a changes in $_ \n"; $a= s/london/London/g; print "$a changes in $_ \n"; $a= s/london/old London/gi; print "$a changes in $_ \n"; bash-2.05b$ perl basic15.pl 1 changes in I love London, but not london or LoNdoN 1 changes in I love London, but not London or LoNdoN 3 changes in I love old London, but not old London or old London Note that the changes themselves have occurred to the $_ variable, while $a stores the number of changes that have been made in each substitution. Remembering Patterns Can use the special RE codes \1,...,\9 to recall matched patterns in the same regular expression or substitution. $_ = "Lord Whopper of Fibbing"; s/([A-Z])/:\1:/g; print "$_\n"; This will replace each upper case letter by that letter surrounded by colons, i.e. :L:ord :W:hopper of :F:ibbing. Can use the special Perl read-only variables $1,...,$9 to recall matched patterns in the rest of the code. if (/(\b.+\b) \1/) { print "Found $1 repeated\n"; } $search = "the"; s/${search}re/xxx/; This will identify any words repeated within $_ This will replace every occurrence of within $_ with xxx. there After a match, you can use the special read-only variables $` and $& and $' to find what was matched before, during and after the search. Some Future Needs s/\+/ /g; s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/ge; s/\+/ /g globally substitutes all literal "+" signs, replacing them with a space. means a % followed by two hexadecimal digits (the numerals 0-9 and the letters A through F). /%([0-9A-F][0-9A-F])/ () groups the two characters followed by %, later use it as $1 hex($1) converts a hexadecimal number in $1 to a hexadecimal string. takes a value and packs it into some sort of data structure. The "c" tells it to put the hexadecimal number into a character. e evaluate the right side as an expression. pack() Translation The tr function allows character-by-character translation. $sentence =~ tr/abc/edf/ This replaces each a with e, each b with d, and each c with f in the variable $sentence, and returns the number of substitutions made. Most of the special RE codes do not apply in the tr function. $count = ($sentence =~ tr/*/*/); This counts the number of asterisks in the $sentence variable and stores that in the $count variable. However, the dash is still used to mean "between". So consider these examples below: tr/a-z/A-Z/; tr/\,\.//; This converts $_ to upper case. This deletes all commas and periods from $_ Split The split function splits up a string and places it into an array. $info = "Caine:Michael:Actor:14, Leafy Drive"; @personal = split(/:/, $info); @personal = ("Caine", "Michael", "Actor", "14, Leafy Drive"); @personal = split(/:/); Operates on the variable $_ @personal = ("Capes", "Geoff", "", "Shot putter", "", "", "Big Avenue"); $_ = "Capes:Geoff::Shot putter:::Big Avenue"; @personal = split(/:/); Can use REs inside of the split function $_ = "Capes:Geoff::Shot putter:::Big Avenue"; @personal = split(/:+/); @personal = ("Capes", "Geoff", "Shot putter", "Big Avenue"); @chars = split(//, $word); @words = split(/ /, $sentence); @sentences = split(/\./, $paragraph) A word into characters A sentence into words A paragraph into sentences Some Future Needs @parameter_list = split(/&/,$result); # split string on '&' characters foreach (@parameter_list) { s/\+/ /g; s/%([0-9A-F][0-9][A-F])/pack("c",hex($1))/ge; } Firstly, we chop the query string up, dividing it on each &, and placing the results in an array of strings called @parameter_list. Secondly, we loop over the array. Each element in the array is in turn implicitly assigned to $_ (the current workspace), and the substitution commands in the loop are applied to $_. Hashes Hashes (associative arrays) are arrays in which each data element is accessed by a string key. %ages = ("Michael Caine", 39, "Dirty Den", 34, "Angie", 27, "Willy", "21 in dog years", "The Queen Mother", 108); $ages{"Michael Caine"}; # 39 $ages{"Dirty Den"}; # 34 $ages{"Angie"}; # 27 $ages{"Willy"}; # "21 in dog years" $ages{"The Queen Mother"}; # 108 On the right we see that each % has changed to a $ (as each individual hash element is a scalar). The index is enclosed in curly braces. Can be converted back into a list array @info = %ages; $info[5]; %moreages = @info; # # # # @info is a list array. It now has 10 elements Returns the value 27 from the list array @info %moreages is a hash. It is the same as %ages Operators Can access all the elements of a hash in turn using the keys function and the values function foreach $person (keys %ages) { print "I know the age of $person\n"; } foreach $age (values %ages) { print "Somebody is $age\n"; } while (($person, $age) = each(%ages)) { print "$person is $age\n"; } if (exists $ages{"The Queen Mother"}) { print "She is still alive\n"; } delete $ages{"The Queen Mother"}; keys returns a list of the keys (indices) values returns a list of the values. In which order? If called in a scalar, return the number of key/value pairs in the hash. each returns a two element list of a key and its value. Every time each is called it returns another key/value pair. exists returns TRUE if the value exists as a key in the hash. delete deletes the specified key and its associated value from the hash. Subroutines Can define and place own functions (subroutines) anywhere in code. sub mysubroutine { print "Not a very interesting routine\n"; print "This does the same thing every time\n"; } A user defined subroutine is called with an & character in front of the name &mysubroutine; &mysubroutine($_); &mysubroutine(1+2, $_); # Call the subroutine # Call it with a parameter # Call it with two parameters A function call isnt type-checked. It may be called with none, one, or several parameters, regardless of how it is defined. Parameters When the subroutine is called any parameters are passed as a list in the special @_ list array variable (also accessible through the $_ variable, which refers to @_ in this local context). sub printargs { print "@_\n"; } &printargs("perly", "king...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

East Los Angeles College - COMP - 519
COMP519: Web Programming Autumn 2008In the next lectures you will learn What is SQL How to access mySQL database How to create a basic mySQL database How to use some basic queries How to use PHP and mySQLIntroduction to SQLSQL is an ANSI (Am
East Los Angeles College - COMP - 202
Learning outcomes COMP202 Complexity of Algorithms Sorting [See Sections 2.4, 4.1, 4.3, and 4.5 in Goodrich and Tamassia.]1. Understand the sorting problem, and its fundamental importance in algorithms. 2. Have a wide knowledge of different types o
East Los Angeles College - COMP - 519
COMP519: Web Programming Autumn 2008PHP Basics: Introduction to PHP a PHP file, PHP workings, running PHP. Basic PHP syntax variables, operators, if.else.and switch, while, do while, and for. Some useful PHP functions How to work with HTML fo
East Los Angeles College - COMP - 519
DatamodelsXML: eXtensible Markup LanguageSlides are based on slides from Database System Concepts Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use Many examples are from www.w3schools.comRDBMS: atomic elements store
East Los Angeles College - COMP - 519
Comp 519: Web Programming Autumn 2008Advanced SQL and PHP Advanced queries Querying more than one table Searching tables to find information Aliasing tables PHP functions for using query resultsUsing several tables mySQL (like any other database
Sveriges lantbruksuniversitet - GEOG - 420
2/20/2009GEOG 420 Lecture 5 feminismsOutline feminist cultural geographiesFeminist cultural geographiesfeminismsSex: biologically male or female Gender: social rendering (e.g. inscription, identification, and enactment) of male and fema
Sveriges lantbruksuniversitet - GEOG - 420
1/16/2009GEOG 420 Lecture 1Outline Environmental determinism Carl Sauer &amp; landscapeOld Cultural Geography The superorganic Important to understand how culture has been used and why it has been used in certain ways History of geography i
Sveriges lantbruksuniversitet - GEOG - 420
1/23/2009GEOG 420 Lecture 2Outline 20th C. human geographies cultural studiesnew cultural geography new cultural geographyspace Late 19th C. and early 20th C. geography explored, identified, described, mapped, classified (Sauer, Hartsho
Sveriges lantbruksuniversitet - GEOG - 420
2/6/2009GEOG 420 Lecture 4 social theoryOutline globalization of capitalism Don Mitchells critiqueMarxist critiquessocial theoryUKCommittee on SOCIAL THEORY The University of Kentucky's Committee on Social Theory was formed in 1989 to
Sveriges lantbruksuniversitet - GEOG - 102
Lect. 4 GEOG 102 Sep. 26, `07 Hertzman1) Comments on Ronald Wright's conclusions 2) Urban heat islands-myths and facts 3) Cities of the Less Developed World &amp; Related Issues1a) Comments on Ronald Wright's conclusionsa) pp. 128-29 RUNAWAY TRAIN i
East Los Angeles College - COMP - 103
CPU Registers in PentiumComputer Systems Lecture 9CPU status flags EFLAG: The Flag register holds the CPU status flags The status flags are separate bits in EFLAG where information on important arising conditions such as overflow, or carry bits
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 4. MORE ON BASIC DATA TYPES1) Pointers 2) Type declarations 3) Access/reference values 4) Type renaming/aliasing 5) Subtypes 6) Macro substitutionPOINTERS Pointer variables have as their value an address, i.e. a refer
East Los Angeles College - COMP - 317
Exponentialsc := 1 ; while b &gt; 0 c := 1 ; while b &gt; 0 while (b a := b := b := b c := c * { c=mn }The Goal{ a=m b=n b 0 }while (b div 2) * 2 = b a := a * a ; b := b div 2 b := b 1 ; c := c * adiv 2) * 2 = b a * a ; b div 2 1 ; aThe Invar
East Los Angeles College - COMP - 205
COMP205 Comparative Programming LanguagesPart 1: Introduction to programming languagesLecture 3: Managing and reducing complexity, program processingMANAGING AND REDUCING COMPLEXITY, AND PROGRAM PROCESSING1. Managing and reducing complexity
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES INTRODUCTION1) Definition2) Note on structured and modular programming, and information hiding 3) Example imperative languages 4) Features of imperative languages(Q) WHAT IS AN IMPERATIVE LANGUAGE? We can define such
East Los Angeles College - COMP - 213
COMP213 Example Exam: Model Solution 1. (a) import java.util.Vector; /* * Trees with integer internal labels and lists of subtrees. * * The {@link TreeNode list of subtrees} is implemented as a linked list. * * @author &lt;a href=&quot;mailto:grant@liverpool
East Los Angeles College - COMP - 213
COMP213DEPARTMENT : Computer ScienceSEPTEMBER 2005 EXAMINATIONSBachelor of Arts : Year 2 Bachelor of Arts : Year 3 Bachelor of Engineering : Year 2 Bachelor of Science : Year 1 Bachelor of Science : Year 2Advanced Object-Oriented Programming
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 5. COMPOUND (HIGHER LEVEL) DATA TYPES I - ARRAYS1) Introduction to higher level types 2) Arrays and their declaration 3) Assigning values to array elements 4) Operations on arrays 5) Ada array attributesINTRODUCTION TO
East Los Angeles College - COMP - 205
Comp 205:Comparative Programming LanguagesDeclarative Programming Languages Logic Programming Horn-Clause Logic PrologLecture notes, exercises, etc., can be found at: www.csc.liv.ac. uk/~grant/Teaching/COMP205/Declarative vs ImperativeDecla
Sveriges lantbruksuniversitet - PHYS - 101
CHAPTER 3: Kinematics in Two or Three Dimensions; Vectors46. Choose the origin to be at ground level, under the place where the projectile is launched, and upwards to be the positive y direction. For the projectile, v0 = 65.0 m s , 0 = 35.0, a y =
Sveriges lantbruksuniversitet - PHYS - 1010901
CHAPTER 3: Kinematics in Two or Three Dimensions; Vectors46. Choose the origin to be at ground level, under the place where the projectile is launched, and upwards to be the positive y direction. For the projectile, v0 = 65.0 m s , 0 = 35.0, a y =
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 12a. ERROR HANDLING1) Causes of errors 2) Classification of errors 3) Signals and exceptionsCAUSES OF ERRORS1) Domain/data errors: an operation is called with data that cannot be handled by that operation, e.g. divide
Sveriges lantbruksuniversitet - COGS - 300
Some material relevant to the Syllogism.First, we should get straight on the four &quot;categorical forms&quot; of statements. They are: A: E: I: O: All X are Y No X are Y Some X are Y Some X are not YThe A, E, I, O are the standard names for the type of st
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 11. PROGRAM CONSTRUCTS 2 (REPETITION)REPETITION Two main forms of repetition: 1) Fixed Count Loops: Repetition over a finite set (for loops). 2) Variable Count Loops: Repetition as long as a given condition holds (whil
East Los Angeles College - COMP - 205
Comp 205:Comparative Programming LanguagesFunctional Programming Languages:T A R L e i s c t u c r s o m i v e p d r e e h f i n e n i t i o s i o n n s s M h e t y p e o f l i s t s i sRecursion r e c u r s i v e l y d e f i n e d :More
East Los Angeles College - COMP - 205
Comp 205:Comparative Programming LanguagesE eErrorsr r o v a l ur s aa t er e s areported w h x n i l l e g a l ee pn r e st h se i o nH :askel li nt er pr et erLazy Evaluation E E I n vr r o a
East Los Angeles College - COMP - 213
COMP 213Advanced Object-oriented ProgrammingLecture 13Propositional Logic(Mondrian )TaskDevelop a program that: allows a user to enter a string representing a term in propositional logic; prints out the term with minimal and maximal bracke
East Los Angeles College - COMP - 205
k y {w } z xwv C #8} w8 D8~&amp;d {| w y D% B 9jSP WQ P FP QuCDPdg 9PfgYpP Q j%5 DeuC 6I#DED5B @85641 Q A BC S A A 9 F B C A97 3 k 94%IDB t 9 P9 BY6m Clengths = map (length) incAll = map (plus 1) where plus m n = m + n # kH l 44 Q %4%3 D4Pd Tr D 9 D
East Los Angeles College - COMP - 213
COMP213DEPARTMENT : Computer ScienceSEPTEMBER 2004 EXAMINATIONSBachelor of Arts : Year 2 Bachelor of Arts : Year 3 Bachelor of Engineering : Year 2 Bachelor of Science : Year 1 Bachelor of Science : Year 2Advanced Object-Oriented Programming
East Los Angeles College - COMP - 213
COMP 213Advanced Object-oriented ProgrammingLecture 5ScopeClassesA class contains declarations of members. Members can be: fields (including constants) methods classes Each of these has a name, as do classes themselves. Every name has a scop
East Los Angeles College - COMP - 205
COMP205 Comparative Programming LanguagesGrant Malcolm (grant@csc.liv.ac.uk) Introduction to programming languages The imperative paradigm The functional paradigm Other paradigms and concluding remarksBOOKS1. Tucker, A. and Noonan, R. Program
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 9. EXPRESSIONS AND STATEMENTS1. Unions 2.Expressions. 3.Operators. 4.Type equivalence. 5.Coercion, casting and conversion.UNIONS It is sometimes desirable to define a variable which can be of two or more different typ
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 6. COMPOUND (HIGHER LEVEL) DATA TYPES II - MORE ON ARRAYS1) Constrained (static) and unconstrained (dynamic) arrays. 2) Flexible arrays 3) Multi-dimensional arrays 4) Arrays of arrays 5) Lists, sets, bags,Etc. 6) Strings
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 14. PROGRAM COMPOSITION II1) More on parameter passing: a) Parameter association b) Default parameters c) Procedures as parameters 2) Modules: Ada packages, C modules, C header files 3) Programs 4) Generics and Abstract
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 2. DATA1) Data Attributes2) Declarations, Assignment and Instantiation 3) Global and Local Data 4) Variables 5) Constants 6) Example programsDATA - &quot;that which is given&quot;A data item has a number of attributes: 1) An A
Cal Poly - MEC - 6304
PERFORMANCE 23 18SWASHPLATESERIES PUMP ANGLETHESE CURVES DO NOT TAKE LOSSES DUE TO THE, CHARGEINTO PUMPACCOUNT
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 3. DATA AND DATA TYPES1) Data Review 2) Anonymous Data Items 3) Renaming 4) Overloading 5) Introduction to Data Types 6) Basic types 7) Range and precision 8) Ada/Pascal &quot;attributes&quot;ANONYMOUS DATA ITEMS Often we use d
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 5. COMPOUND (HIGHER LEVEL) DATA TYPES I - ARRAYS1) Introduction to higher level types 2) Arrays and their declaration 3) Assigning values to array elements 4) Operations on arrays 5) Ada array attributesINTRODUCTION TO
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 6. COMPOUND (HIGHER LEVEL) DATA TYPES II - MORE ON ARRAYS1) Constrained (static) and unconstrained (dynamic) arrays. 2) Flexible arrays 3) Multi-dimensional arrays 4) Arrays of arrays 5) Lists, sets, bags,Etc. 6) Strings
East Los Angeles College - COMP - 205
COMP205 Comparative Programming LanguagesGrant Malcolm (grant@csc.liv.ac.uk) Introduction to programming languages The imperative paradigm The functional paradigm Other paradigms and concluding remarksBOOKS1. Tucker, A. and Noonan, R. Program
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 11. PROGRAM CONSTRUCTS 2 (REPETITION)1) Fixed count loops 2) Variable count loops 3) Post-test Loops 4) Terminating a loopREPETITION Two main forms of repetition: 1) Fixed Count Loops: Repetition over a finite set (fo
Sveriges lantbruksuniversitet - M - 251
Homework #1 MATH 251 Coordinates in Three Dimensions a) Describe the geometry of the set of points whose coordinates (x, y, z) satisfy the equation: x2 + y 2 + z 2 + 4x + 2y 6z 22 = 0 . b) Show that the intersection of the object in part a) with
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 7. COMPOUND (HIGHER LEVEL) DATA TYPES III1) Enumerated types 2) 3) 4) 5) 6) Records and structures Accessing fields in records/structures Operations on records/structures Variant records Dynamic and static arrays of reco
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 9. EXPRESSIONS AND STATEMENTS1. Unions 2.Expressions. 3.Operators. 4.Type equivalence. 5.Coercion, casting and conversion.UNIONS It is sometimes desirable to define a variable which can be of two or more different typ
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 12a. ERROR HANDLING1) Causes of errors 2) Classification of errors 3) Signals and exceptions12b. PROGRAM COMPOSITION I1) Program hierarchy 2) Blocks 3) Routines 4) Procedures and functionsCAUSES OF ERRORS1) Domain/
Sveriges lantbruksuniversitet - MATH - 443
MATH 443 Assignment #7Below are short answers (hints) to assigned questions.19A(i) There are 6 = 15 points in the incidence structure. Consider two 2 distinct edges of K6 . If they have a common endpoint, they belong to a unique triangle, and to
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES INTRODUCTION1) Definition2) Note on structured and modular programming, and information hiding 3) Example imperative languages 4) Features of imperative languages(Q) WHAT IS AN IMPERATIVE LANGUAGE? We can define such
East Los Angeles College - COMP - 205
COMP205 Comparative Programming LanguagesPart 1: Introduction to programming languagesLecture 3: Managing and reducing complexity, program processingMANAGING AND REDUCING COMPLEXITY, AND PROGRAM PROCESSING1. Managing and reducing complexity
East Los Angeles College - COMP - 205
TYPE EQUIVALENCE1) Coercion 2) Casting 3) ConversionCOERCION Operators require their operands to be of a certain type (similarly expressions require their arguments to be of the same type). In some cases it may be appropriate, when a compiler fi
Sveriges lantbruksuniversitet - MATH - 202
MACM 202 Assignment 3, Spring 2004Luis Goddyn and Michael MonaganThis assignment is worth 10% of your grade. It is due Friday February 18th at beginning of class. A late penalty of 20% will apply for each day late. Do question: Either 1 or 2 , eith
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 4. MORE ON BASIC DATA TYPES1) Pointers 2) Type declarations 3) Access/reference values 4) Type renaming/aliasing 5) Subtypes 6) Macro substitutionPOINTERS Pointer variables have as their value an address, i.e. a refer
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 13. PROGRAM COMPOSITION II1) Scope a] Ada scope rules b] C scope rules 2) Parameter passing a] Ada parameter modes b) Parameter passing mechanismsSCOPE RULES Scope rules govern the visibility and life time of data ite
Sveriges lantbruksuniversitet - MATH - 443
MATH 443 - Assignment #3Below are short answers (hints) to assigned questions.14EFix one edge, say e, of the convex (n + 1)-gon. For any particular dissection into quadrilaterals consider the quadrilateral &quot;supported&quot; by edge e. The remaining thr
East Los Angeles College - COMP - 205
Comp 205:Comparative Programming Languages FunctionalProgrammingLanguages:MoreLists Recursivedefinitions Listcomprehensions Lecturenotes,exercises,etc.,canbefoundat: www.csc.liv.ac.uk/~grant/Teaching/COMP205/RecursionThetypeoflistsisrecursive
Sveriges lantbruksuniversitet - MATH - 820
TSP Lower BoundsLuis Goddyn, Math 408 We give here two techniques for obtaining lower bounds on TSP instances. That is, for a given instance (V, d), we would like to find the largest possible number t such that (T ) t for every TSP tour T . We firs
Sveriges lantbruksuniversitet - MATH - 445
A SAMPLE MATH DOCUMENTJOHN DOE, MATH 445, FALL 2006This is a sample input le. Comparing it with the output it generates can show you how to produce a simple document of your own. 1. Ordinary Text The ends of words and sentences are marked by space
Sveriges lantbruksuniversitet - MATH - 820
TSP HeuristicsLuis Goddyn, Math 408 There are two types of heuristic methods for finding optimal TSP tours. Scratch methods produce an initial tour which is hopefully fairly close (say 10%) from being optimal. Improvement methods (sometimes called p
Sveriges lantbruksuniversitet - MATH - 445
Homework 7 SolutionsOuterplanar A graph G is outerplanar if it can be drawn in the plane so that all vertices lie on the infinite face. 1. Show that G is outerplanar if and only if G has no K2,3 or K4 minor. Solution: Let G+ be the graph obtained fr
Sveriges lantbruksuniversitet - MATH - 820
Exercises for Math 820 Luis Goddyn 1. Let w : V {0, 1, 2, . . .} be a weighting of the vertices of an undirected graph G = (V, E). Describe an algorithm which either nds an orientation of G for which each vertex v has out-degree exactly + (v) = w(v
Sveriges lantbruksuniversitet - MATH - 443
MATH 443 - Assignment #5Below are short answers (hints) to assigned questions.37ALet C denote the group of rotations of the cube. Following the description of elements of C in Appendix 1 we find that the cycle index of the action of C on the six
Sveriges lantbruksuniversitet - MATH - 445
Higher Surfaces I: embeddings and the torusIn this section, graphs are permitted to have loops and parallel edges. Surface: A surface is a topological space which appears locally like the plane. More precisely, for every point x in the surface, ther