week five agenda

48

Upload: clare-farley

Post on 01-Jan-2016

19 views

Category:

Documents


0 download

DESCRIPTION

Week Five Agenda. Announcements Link of the week Review week four lab assignment This week’s expected outcomes Next lab assignment Break-out problems Read assignments Upcoming deadlines Lab assistance, questions and answers. Announcements. - PowerPoint PPT Presentation

TRANSCRIPT

Week Five Agenda

•Announcements•Link of the week•Review week four lab assignment•This week’s expected outcomes•Next lab assignment•Break-out problems•Read assignments•Upcoming deadlines•Lab assistance, questions and answers

Announcements• The midterm and the final exam are both

electronic. Please verify that your testing facility can administer this type of test.

• The midterm exam will be February 18 through 23, 2013.

• The midterm exam outline has been sent to both ITEC 400 sections.

Link of the weekData Disaster Ontrack Data Recoveryhttp://www.ontrackdatarecoveryIronkey USB Flash Drivehttps://www.ironkey.com/demo-enterpriseData Disaster Helpful Hints

- Use dedicated circuits for your connection- Keep your computer cool and in a dry place- Use a UPS (Uninterrupted Power Supply)- Don’t assume that your data is permanently

destroyed even if the situation looks bad- Secure your work area and devices

Link of the week

Data Disaster

1.Big and small company operations

2.Backup services

3.Trouble shooting

4.Data recovery

Review week four lab assignment

What is an object file?

Object code is a representation of code generated by a compiler after it processes a programming language code file. It contains compact, pre-parsed code, often referred to as binaries that can be linked with other object files to generate a final executable.

Review week four lab assignment

What is ELF?

Executable and Linking Format (ELF) is a common standard file format for executables, object code, shared libraries, and core dumps.

Review week four lab assignment

Online Documentation

Websites that have Perl documentation. The two biggest ones are:

http://perldoc.perl.org/

http://search.cpan.org/ for modules

Review week four lab assignmentPerl Syntax

; End of statement delimiter, Comma for line continuation \n New line (non-printable character)<> The "diamond operator", <> is

used when a program is expecting input, but isn't concerned how it arrives.

Demonstrate: diamond_oper.pl <file name> diamond_oper.pl

Review week four lab assignmentPerl Variable Syntax

$ Singular variables prefix (single value, number or string)

@ Prefix for plural variable (array)% Prefix for plural variable (hash)$_ Default variable It Is the "it" variable. It's often the default parm that built-in functions use, or return into.$0 Contains the name of the program

being run

Review week four lab assignmentPerl Syntax

while ( … ){

Action statements}

What is a continuous loop?while ( 2 ) {

Action statements}

Demonstrate: perl_it.pl

Review week four lab assignmentPerl SyntaxIf ( … )

{Action statements

}elsif{

Action statements}

Review week four lab assignmentPerl Syntax

The Perl language does not support case or switch statements. The closest way to achieve case evaluations is as follows:

if ( $condition_one ) {         action_one ();    }    elsif ( $condition_two ) {        action_two ();    }    ...    else {        action_n ();    }

Review week four lab assignmentPerl SyntaxIf ( …)

{ Action statements

}

Review week four lab assignmentThree Types of for loopsmy @array;

# Old style C for loops

for (my $i = 0; $i < 10; $i++) {        $array[$i] = $i;    }

# Iterating loops    for my $i (@array) {        print "$i\n";    }

Review week four lab assignmentThree Types of for loops (continued)# Postfix for loops

    print "$_\n" for @array;

Review week four lab assignmentPerl Syntax

foreach $total (12,9,3,7)

{

# Sum each value in the list.

$sum += $total;

}

Review week four lab assignmentPerl Syntaxforeach (-32,10,1,2,0,-1) {

# Valid numbers are considered to be greater than zero

# The default variable is utilized,

if ( $_ > 0 )

{

# Print each valid number on a single output line.

print "$_\n";

}

}

Review week four lab assignmentRelational OperatorsNumeric String Meaning > gt Greater than >= ge Greater than or

equal to < lt Less than <= le Less than or equal

to

Review week four lab assignment

Equality Operators

Numeric String Meaning

== eq Equal to

!= ne Not equal to

cmp Comparison with signed result

The or cmp operators return 1 if the left operand is less than the right operand, 0if they are equal, and +1 it the left operand is greater than the right.

Review week four lab assignmentDefinition: array

Arrays are an ordered list of scalars, accessed by the scalar’s position in the list. Otherwise known as a collection of scalars. In Perl, a scalar means the simplest data type which was designed to hold only one thing like a number, a string or a reference.

Elements in an array are accessed by using an index. Array indexes start with zero.

Review week four lab assignment

Array and Variable InitializationInitialize an array:

@garage = (“rake”, “mower”, “shovel”);

@persons = (“Will”, “Ken”, “Hazel”, “Jay”);

$count = @persons;

Unload array elements into variables:

($rake, $mower, $shovel) = @garage

Review week four lab assignmentArray Data Structures

Array of arrays – Two-dimensional array or a matrix

@names = (

[ “Brenda”, “Clide”, “Kim” ],

[ “Melinda”, Terri”, “Sissy” ],

[ “Fred”, “Omar”, “Vincent” ] );

print $names [1] [1];

Demonstrate: ~dandrear/Winter_2013_Solutions/two_dim.pl

Review week four lab assignment

Definition :Hash (associative array)

A hash is similar to an array only because it contains a number of scalars. A hash is different in the case where the element of a structure represents a pair – a key and a value. Whenever we refer to an element of a Perl hash structure, we mean a pair (key and value) which links a value to a key. We have access to the elements of a hash variable by a scalar key.

Hash table is an unordered set of scalars, accessed by some string value that is associated with each scalar.

Review week four lab assignmentHash Initialization

%student_ages = ("John", 43, "Paul", 25, "Marie", 22);

%members = (John => "father", Paul => "son", Marie => "daughter");

The comma-arrow (=>) operator is used to initialize the %members hash variable in the second line of code. The left side of the comma-arrow operator is expected to be a simple string and therefore it is not necessary to be quoted.

Review week four lab assignmentHash Initialization (con’t)

%all_groups = (

group_name1 => [ “Betty”, “Tom”, “Moe” ],

group_name2 => [ “Ali”, “Marcia”, “Sis” ]

);

$all_groups{group_name1} [3] = “Sam”;

for $couple ( keys %all_groups ) {

print “$couple; @{$all_groups{$couple} }\n;

}

Review week four lab assignment

Hash Copy

%school_ages = %student_ages

Demonstrate: ~dandrear/Winter_2013_Solutions/hash_tbl.pl

Review week four lab assignment

Hash Table Example%colormap=(

“12” => “gray”,“19” => “black”,“30” => “red”,);

%colormap = (“12”, “gray”, “19”, “black”, “30”, “red”);

Review week four lab assignment

BLACK RED GRAY

YELLOW BLUE WHITE

GREEN AMBER GOLD PINK

11 12 13

21 22 23

31 343332

Hash Table

Review week four lab assignment

SourceFile

SourceFile

SourceFile

SourceFile

SourceFile

Object File

Object File

ObjectFile

Object File

ObjectFile

LinkerRuntimeLibrary

ExecutableProgram

Source/Object/Executable Drawing

Review week four lab assignment

Perl utilizes two types of categories- Singular variables that represent a single-

value. The variable prefix symbol for a scalar is the $.

- Plural variables are ones that contain multiple-values. Arrays and hashes are two multi-valued variables.

Review week four lab assignment

Perl data types $answer = 42; (an integer)

$pi = 3.14159265; (a “real” number)$animal = “horse”; (string)$statement = “I exercise my $animal”; (string

with interpolation)$amount = ‘It cost me $5.00’; (string

without interpolation)$cwd = `pwd`; (string

output from a command)Perl utilizes dynamic data typing of variables.

Review week four lab assignment• Filehandle is utilized for both input and output files.

Most file names are cryptic and are meaningless to programmers. The purpose of a filehandle is to help the programmer remember a simple file name throughout a program.

A filehandle is a name given for a file, device, socket, or pipe.

Filehandle command line format:

open(filehandle, file name, permissions, chmod);

Example: open($FH,$file_name);

Review week four lab assignment

• Practice scripts under the system /tmp directory.

awksrc.sh diamond_oper.pl

person.sh perl_it.pl

two_dimen.pl names

hash_table.pl test_build.sh

perl_prt.pl

Weeks four and five expected outcomes

• Write Perl scripts, including variables, control flow, and regular expression syntax

Next lab assignment

Regular Expressions

Search programs – grep, egrep, and findstr.

Text language programs - sed and awk

Text editors – iv, ed, and emac

Many other languages use regular expressions and may advertise a particular version of Perl.

Next lab assignmentRegular Expression Special Characters * Open square bracket [ * Backslash \

* Caret ^* Dollar sign $* Dot .Pipe symbol |Question mark ?Asterisk ** Plus sign +Opening and closing round brackets ( )

Next lab assignmentRegular Expression (a.k.a. regex or regexp)

Is a pattern that describes a certain amount of text. A basic regular expression could be the single character, e.g.: a

Jack is a guy.

It will match the first occurrence in the string. If succeeding matches are desired, the regex engine must be instructed to do so.

Next lab assignment

Character Classes match only one out of several characters, e.g.: [ae] and gr[ae]y

The order of the characters inside a character class doesn’t matter.

Shorthand Character Classes match single

characters, e.g.: \d and \w and \s and \t

Non-Printable Characters are special character sequence to put non-printable characters in your regular expression, e.g.: \t and \r and \n and \a and \e and \v

Next lab assignment

Dot matches almost any character, except line break characters, e.g.: gr.y

Anchors match a position.

Match start of string ^

Match end of a string $

Alternation is the regular expression equivalent of “or”. The search pattern bird | insect will first return “bird. The second match will be “insect”.

Next lab assignmentnames

Bob D'Andrea 222-40-1234 03/19/1947 male

Bo Happy 444-20-2222 01/01/1945 male

Jane Smith 324-78-9990 04/23/1978 female

Razi Jake 564-54-9879 05/26/2005 male

The file named “names” contains the above information.

There are tabs in two places in the above data. One tab is after the name and after the birth date.

Next lab assignmentWithout options, print the desired fields in any order.

awk ‘{ print $1, $2, $3, $4 }’ names

The –F option changes the field separator on the command line. The \t is an Escape Sequence for a horizontal tab.

awk –F”\t” ‘{ print $1 }’ names

Next lab assignmentmakefile Lab Assignment

Copy the test_build.sh script from /tmp directory.

This script executes the make command which in turn executes the makefile.

Demonstrate:

~dandrear/temp/test_build.sh

Display the test_build.sh script

Next lab assignmentProgramming Perl, Chapter 32 Standard ModulesDefine: ModuleParsing the command line with Getopt::StdExample: listdir –l –n –a 10:00 bottom topPerl utilizes @ARGV to capture the command line

argumentsExample: $ARGV[0] ‘-l’

$ARGV[1] ‘-n’ $ARGV[2] ‘-a’ $ARGV[3] ’10:00’ $ARGV[4] ‘bottom’ $ARGV[5] ‘top’

Break-out problems• Define a Perl hash table• Define ELF• Define a Perl array• What convenience does a Perl filehandle provide?• What is the functionality of a regular expression? • Are continuous loops useful?• Define an object file• Define common-arrow• Perl default variable• Perl “it” variable

• Explain the s/pattern/new version/ command

Reading assignments• Reading Assignment

Essential System Administration

Chapter One

Chapter Two

Chapter Three

Programming Perl

Chapter One

Chapter Two

Chapter Three

Chapter Four

Chapter Thirty Two (review)

Upcoming deadlinesLab Assignment 6-1 due February 18, 2013

Lab Assignment 5-1 due February 25, 2013

Lab Assignment 7-1 (midterm) has to be completed by.

Midterm exam will be administered from February 18 through 23.

Midterm outline has been emailed to all students.

Questions and answers

• Questions

• Comments

• Concerns

• After class I will help students with their scripts.