180 likes | 320 Vues
IT441 Network Services Administration. Prof. Alfred J Bird, Ph.D., NBCT abird@cs.umb.edu http:// it441-s14-bird.wikispaces.umb.edu / Door Code 536587* Office – McCormick 3rd floor 607 Office Hours – Tuesday & Thursday 4:00Pm to 5:15PM. Program Comments. Start a comment with a #
E N D
IT441Network Services Administration Prof. Alfred J Bird, Ph.D., NBCT abird@cs.umb.edu http://it441-s14-bird.wikispaces.umb.edu/ Door Code 536587* Office – McCormick 3rd floor 607 Office Hours – Tuesday & Thursday 4:00Pm to 5:15PM
Program Comments • Start a comment with a # • Write many comments in your program • Write a header block in EVERY program # # Author: Al Bird # Name: firstName.pl # Date: 11 Sept 2013 # Purpose: To solve a problem #
Four Domains of Programming Languages • Input / Output
Four Domains of Programming Languages • Input / Output • Variables / Information Storage
Four Domains of Programming Languages • Input / Output • Variables / Information Storage • Decision / Control Structures
Four Domains of Programming Languages • Input / Output • Variables / Information Storage • Decision / Control Structures • Data Manipulations / Calculations
Variables • What is a variable? • How do we name variables? • Starts with $ • Next either letter or _ • Rest can be letters or numbers • You should develop a pattern so you are consistent within your programs. • $userFirstName • $user_first_name • Make the name mean something!!!
Getting Data into the Program • Use the file handle <STDIN> • Use the chomp() function • chomp (my $newInput = <STDIN>);
Numerical Comparisions • == Equality • < Less Than • <= Less Than or Equal To • > Greater Than • >= Greater Than or Equal To
Arithmetic Comparisons • $x > $y • $x < $y • $x >= $y • $x < =$y • $x == $y • $x != $y
String Operators • . Concatenation • x Repetition • ord() ASCII Value of a character • lt Less Than • gt Greater Than • eq Equal To
String Comparisions • $x gt $y • $x lt $y • $x ge $y • $x le $y • $x eq $y • $x ne $y
Logical Operators • $x and $y • $x && $y • $x or $y • $x || $y • Not $x • !$x
Ways to get out of a program • exit (0); • die $string;
If Statements • if • if ( condition ) { action }
Programming Exercises • Write a program to: • Input two numbers • Add, subtract, multiple and divide them • Write out the results in a formatted form i.e 3.7 + 4.1 = 7.8 3.7 – 4.1 = -0.4 • Write a program to: • Store a password in a variable • Input a string • Compare the stored password to the inputted string • Write a success or failure message
Programming Exercises • Write a program to: • Read in two numbers • Decide which is larger • Print out the lower number then the higher number • Write a program to: • Read in five words • Sort them in ASCII order • Print out the five words in ASCII order