it441 network services administration n.
Skip this Video
Loading SlideShow in 5 Seconds..
IT441 Network Services Administration PowerPoint Presentation
Download Presentation
IT441 Network Services Administration

Loading in 2 Seconds...

play fullscreen
1 / 49

IT441 Network Services Administration - PowerPoint PPT Presentation

  • Uploaded on

IT441 Network Services Administration. Prof. Alfred J Bird, Ph.D., NBCT http:// / Office – McCormick 3rd floor 607 Office Hours – Tuesday and Thursday 4:00PM to 5:15PM. Scalars. What is a Scalar? Types of Scalars: Numbers Strings

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'IT441 Network Services Administration' - kitra

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
it441 network services administration

IT441Network Services Administration

Prof. Alfred J Bird, Ph.D., NBCT

Office – McCormick 3rd floor 607

Office Hours – Tuesday and Thursday 4:00PM to 5:15PM

  • What is a Scalar?
  • Types of Scalars:
    • Numbers
    • Strings
    • Logical or Boolean
  • Automatic conversion between types
numbering systems
Numbering Systems
  • Decimal
  • Binary
  • Octal
  • Hexadecimal
constant literal
Constant (Literal)
  • What is a constant?
  • Why do we use a constant?
  • Write a simple program to print out a few constants.
  • Single quoted vs. Double quoted strings
  • 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.
  • Make the name mean something!!!
numeric operators
Numeric Operators
  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • ** Exponentiation
  • % Modulo (Remainder)
boolean operators
Boolean Operators
  • && And
  • || Or
  • ! Not
numerical comparisions
Numerical Comparisions
  • == Equality
  • < Less Than
  • <= Less Than or Equal To
  • > Greater Than
  • >= Greater Than or Equal To
string operators
String Operators
  • . Concatenation
  • x Repetition
  • ord() ASCII Value of a character
  • lt Less Than
  • gt Greater Than
  • eq Equal To
string comparisions
String Comparisions
  • $x gt $y
  • $x lt $y
  • $x ge $y
  • $x le $y
  • $x eq $y
  • $x ne $y
a couple of more things
A Couple of More Things
  • $a++ Autoincrement
  • $b-- Autodecrement
  • Scoping: Blocks of code limit the range of a variables definition


print $numDef;

{ my $numDef=1;

print $numDef;}

print $numDef;

ways to get out of a program
Ways to get out of a program
  • exit (0);
  • die $string;
increment decrement
  • A very helpful construct is the increment/decrement statement
  • $i++ is equivalent to $i = $i+1
    • $j = $i++
    • $j = ++$i
    • $j = $i - -
    • $j = - - $i
logical operators
Logical Operators
  • $x and &y
  • $x && $y
  • $x or $y
  • $x || $y
  • not $x
  • !$x
control flow constructs
Control Flow Constructs
  • What is a control statement?
  • Types of control statements:
    • if
    • while
    • for
if s tatements
If Statements
  • if
    • if ( condition ) { action }
  • if else
    • if (condition ) { action }
    • else {another action }
  • if elsif else
    • if ( condition ) { action }
    • elsif (another condition ) { another action }
    • else { a further action }
if statements cont
If Statements (cont)
  • unless statement

unless (condition) {action};

  • Reversed order

print “Hello Al\n” if($inputName = “Al”);

die “Can’t divide by zero\n:” if ($num4 == 0);

while statement
While Statement
  • while loops
  • while ( condition ) { action }
    • $i=1;
    • while ($i<=5) {
    • print $i, “\n”;
    • $i++;
    • }
  • until loops
    • Same form but opposite action of the while loop
an interesting variable
An interesting variable
  • $_ is the default variable for many functions
  • while ( $line = <STDIN>) {
    • chomp ($line);
    • }
  • while (<STDIN>) {
    • chomp;
    • }
breaking out of a loop
Breaking Out of a Loop
  • There are three ways to modify the execution of the loop:
    • last;
    • next;
    • redo;
  • Statement labels
    • Labels a location in the program
    • Best to use all uppercase letters

OUTER: while(…) {


another form of loops
Another Form of Loops
  • do { action } while ( condition );
  • do { action } until ( condition );
for statement
For statement
  • for loop
  • for ( init_exp ; test_exp; step_exp) { action }
    • for ($i=1; $i<5; $i++) {print $i, “\n”;}
foreach loop
Foreach loop
  • foreach my $number (1..10) {
    • print “The number is: $number \n”;
    • }
alternative string delimiters
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
operators on strings and numbers
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;
math operators
Math Operators
  • ** Exponentiation
  • - Unitary Negation
  • * Multiplication
  • / Division
  • % Modulo (Remainder)
  • + Addition
  • - Subtraction
getting data into the program
Getting Data into the Program
  • Use the file handle <STDIN>
  • Try this out

print “Input something:”;

my $newInput=<STDIN>;

print $newInput;

  • chomp ($newInput);
  • chop($newInput);
a better way
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 $!;
using a filehandle
Using a filehandle
  • To use a filehandle you wrap it in angle brackets.
  • print OUT1 “Hello World!\n”;
  • chomp ($in = <IN1>);
i o redirectors
I/O Redirectors
  • Remember what the redirectors do:
    • >
    • >>
    • <
comment blocks
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.
comment blocks1
Comment Blocks

#!/usr/bin/perl -w


#Module Name:


#Written by Alfred J Bird, Ph.D., NBCT

#Date Written – 21 September 2011

#Purpose: To print out the string “Hello world!”


#Date Modified – 25 September, 2011

#Purpose of modification: To fix spelling errors.

#Modified by: Al Bird


print “Hello world! \n”;

data types
Data Types
  • Remember there are three basic data types in Perl
    • Numeric
    • String
    • Boolean (Logical)
  • I differentiate between data types and data structures. Not every author or teacher does. Some books use the terms interchangeably so watch out!
data structures
Data Structures
  • In PERL there are three types of data structures:
    • Scalars
    • Arrays
    • Hashes
  • Each structure has it own naming syntax.
    • $scalar
    • @array
    • %hash
  • I do not consider a list a data structure but some authors, teachers and CS pros do so be careful .
  • A list is defined as an ordered set of scalar values.
  • Lists are delimited by parentheses such as
    • ()
    • (1)
    • (“a”)
    • (1, 2, 3, 4, 5)
    • (“a”, “b”, “c”, “d”, “e”)
    • (‘e’, ‘d’, ‘c’, ‘b’, ‘a’)
  • Remember that a list is ordered!
using a list
Using a List
  • You have already been using lists without knowing it.
  • When you type the following statement

print (“Hello ”, “world”, “! “, “\n”);

You are passing a list to the print function.

  • I have just used a new Perl term, function.
  • A function is subroutine (a free standing piece of code) or an operator that returns a value and/or does something
another way to create a list
Another Way to Create a List
  • Given a list we created this way:

(‘Hello’, ‘world.’, ‘I’, ‘am’, Al’)

  • We can use another method to create it:

qw/Hello world I am Al/

  • As with earlier similar operators we can use any nonalphanumeric character as a separator:

qw#Hello world I am Al#

qw&Hello world I am Al&

qw{Hello world I am Al}

a third way to create a list
A Third Way to Create a List
  • We can create a list by using a range.
    • This list (1, 2, 3, 4, 5, 6)
    • Is the same as this list (1..6)
  • But this will not work:
    • (6..1) does not give (6, 5, 4, 3, 2, 1)
    • because the left hand side must be less than the rhs
  • To get the list (6, 5, 4, 3, 2, 1) using a range we need to type reverse (1..6)
  • Try these using a print statement!
printing a list
Printing a List
  • Remember that a list is ordered!
    • The elements have a location that can be counted
      • The counting starts with 0 (the 1st element is number 0)
  • How do we print a list?
  • What is the result of the following statements?

print (qw/a b c d e f g/);

  • How about this statement?

print qw/a b c d e f g/;

  • First predict the results and then try them and see what happens.
printing individual list elements
Printing Individual List Elements
  • We can refer to individual elements in a list by using a number in brackets [] after the list.
  • What is the result of the following statement?

print ((qw/a b c d e f g/)[2]);

  • How about this statement:

print ((‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’) [3]);

  • First predict the results and then try them and see what happens.
  • You can put a scalar variable into the braces

$i = 3;

print ((qw/a b c d e f g/)[$i]);

a list slice
A List Slice
  • We can refer to a range inside the braces.
  • What do we get when we run the following statement:

print ((qw/a b c d e f g/)[2..4]);

  • First predict the results and then run the statement.
  • What about this statement:

print ((qw/a b c d e f g/)[3..1]);

  • What do you think will happen if you enter the following code:

print ((‘z’, ‘x’, ‘c’, ‘v’, ’b’, ‘n’, ‘m’)[-1]);

  • First make a prediction and then run the code.
  • How about this code


print ((‘z’, ‘x’, ‘c’, ‘v’, ’b’, ‘n’, ‘m’)[$i]);

  • First make a prediction and then run the code.
another data structure
Another Data Structure

The problem with a list is that it cannot be named!

We need to retype the list every time we want to use it.

To solve this difficulty we have a data structure called an array.

We can give an array a name that starts with a @.

  • An array is a data structure that has the characteristics of a list but can be named!
  • To store a scalar into a variable we use an assignment statement $a = 1;
  • To store a list into an array we do the same thing:
    • @a = (1,2,3,4,5);
    • @l = (‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’);
    • @m = qw<az x c v b n m>;
accessing individual elements
Accessing Individual Elements

How do we access an individual element in an array?

Just like we did in a list.

  • Using a list if we code:

print ((‘now’, ‘is’, ‘the’, ‘time’)[2]);

    • It will print out the
  • Likewise if we define an array:

@s = (‘now’, ‘is’, ‘the’, ‘time’);

print @s[2];

    • Will also print out the
    • What about print $s[2];? What will it print out?
scalar vs list context
Scalar vs. List Context
  • Why does the statement print $s[2]; work?
  • Use the prefix for what you want not what you have.
  • This is referred to as list vs. scalar context.
  • It can become a very important concept later.
array functions
Array Functions
  • How do we add data to an array?
    • @array = (@array, $scalar); #is one way!
  • But there is a better way!!
    • push @array, $scalar; #will do the same thing!
  • push will append the value in $scalar to the top of @array
  • Likewise pop will take the last value in an array and do something with it.
    • $scalar = pop @array
array functions1
Array Functions
  • push() and pop() act on the top of an array (the highest indexed end)
  • shift() and unshift() act on the bottom of an array and perform the same function.
  • We already know what reverse() does.
array functions2
Array Functions
  • Another function is sort().
    • What do you think it does?
    • Write a simple program to try it with your array of months.
      • Predict the output before you try it.
      • What happened?
    • Now write a simple program to try it with your array of number of days.
      • Predict the output before you try it.
      • What happened?????
      • Why?????