1 / 13

IT441 Network Services Administration

IT441 Network Services Administration. Prof. Alfred J Bird, Ph.D., NBCT abird@cs.umb.edu http:// it441-s14-bird.wikispaces.umb.edu / Office – McCormick 3rd floor 607 Office Hours – Tuesday and Thursday 4:00PM to 5:15PM. Last Class Programming Challenges.

hamlin
Download Presentation

IT441 Network Services Administration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IT441Network Services Administration Prof. Alfred J Bird, Ph.D., NBCT abird@cs.umb.edu http://it441-s14-bird.wikispaces.umb.edu/ Office – McCormick 3rd floor 607 Office Hours – Tuesday and Thursday 4:00PM to 5:15PM

  2. Last Class Programming Challenges • A program to print out a list of the squares and cubes of the numbers from 1 to 20. • A program to ask for a number and test if it is a prime number. • A program to ask for two numbers and print out the sum of the numbers until it is told to stop. • A program to chose a specific action based upon an alpha input.

  3. 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 block at the beginning of your code which includes your name, the name of the module, date written and the purpose of the code.

  4. Alternative String Delimiters • q// single quoted string • qq// double quoted string • In qq// the // can be replaced with any other non-alphanumeric character provided you use the same character on both ends of the string

  5. Operators on Strings and Numbers • $a = “123” • $b = “456” • What do we get if we write this line of code, • print $a + $b; • How about this line of code, • print $a . $b;

  6. Math Operators • ** Exponentiation • - Unitary Negation • * Multiplication • / Division • % Modulo (Remainder) • + Addition • - Subtraction

  7. What is an Algorithm • In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning. In simple words an algorithm is a step-by-step procedure for calculations.

  8. File Operations • To use a file we need to attach a filehandle to it. • We do this using the open statement. • A simple example: • open (OUT1, “>testoutout.txt”); • If we open it we want to close it after we are done: • close (OUT1); • By convention a filehandle is codded in all capital letters

  9. A better way • We want to know for sure that we were successful opening the file so we include a test: • open (OUT1, “>>test.txt”) or die $!;

  10. Using a filehandle • To use a filehandle you wrap it in angle brackets. • print OUT1 “Hello World!\n”; • chomp ($in = <IN1>);

  11. I/O Redirectors • Remember what the redirectors do: • > • >> • <

  12. Three problems to code • Calculate the first 50 prime numbers and write them to an output file. • Calculate the first 40 members of the Fibonacci Series and write them to an output file. • Read the two output files and print them to the screen.

  13. Next Time • Read pages 179 to 185 in the Perl book • Complete the three programs

More Related