Programming Perl in UNIX Course Number : CIT 370 Week 6 Prof. Daniel Chen.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

Introduction to C Programming
Advanced Perl WUC Perl Poetry Variable Scope.
Programming Languages and Paradigms
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Programming Languages and Paradigms The C Programming Language.
Objected Oriented Perl An introduction – because I don’t have the time or patience for an in- depth OOP lecture series…
Kernighan/Ritchie: Kelley/Pohl:
Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type.
Objectives In this chapter, you will:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
VBA Modules, Functions, Variables, and Constants
Loose endsCS-2301, B-Term “Loose Ends” CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd.
Chapter 10 More on Modular Programming and Functions.
"Loose ends"CS-2301 D-term “Loose Ends” CS-2301 System Programming C-term 2009 (Slides include materials from The C Programming Language, 2 nd edition,
Scripting Languages Perl Chapter #4 Subroutines. Writing your own Functions Functions is a programming language serve tow purposes: –They allow you to.
Topic R3 – Review for the Final Exam. CISC 105 – Review for the Final Exam Exam Date & Time and Exam Format The final exam is 120-minutes, closed- book,
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Guide To UNIX Using Linux Third Edition
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
Overview scope - determines when an identifier can be referenced in a program storage class - determines the period of time during which that identifier.
Lecture From Chapter 6 & /8/10 1 Method of Classes.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Programming Perl in UNIX Course Number : CIT 370 Week 4 Prof. Daniel Chen.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormack 3rd floor 607.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
Chapter 6: User-Defined Functions
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Visibility, Accessibility, and Information Hiding.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Lecture 13: Working with Multiple Programmers. Headers Header files: Each standard library has a corresponding header. The function prototype for all.
Perl Chapter 6 Functions. Subprograms In Perl, all subprograms are functions – returns 0 or 1 value – although may have “side-effects” optional function.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Programming Perl in UNIX Course Number : CIT 370 Week 3 Prof. Daniel Chen.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
Functions Chapter 6. Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Department of Electronic & Electrical Engineering Functions Parameters Arguments Pointers/dereference & * Scope Global/Local Storage Static/Automatic.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
Programming Perl in UNIX Course Number : CIT 370 Week 2 Prof. Daniel Chen.
APS105 Functions (and Pointers) 1. Modularity –Break a program into manageable parts (modules) –Modules interoperate with each other Benefits of modularity:
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Names and Attributes Names are a key programming language feature
Visibility, Accessibility, and Information Hiding
Objectives In this chapter, you will:
Enumeration Type Data type: a set of values with a set of operations on them Enumeration type: a simple data type created by the programmer To define an.
Programming with ANSI C ++
Perl Modules.
This pointer, Dynamic memory allocation, Constructors and Destructor
© 2016 Pearson Education, Inc.,Hoboken, NJ. All rights reserved.
Subroutines Web Programming.
Introduction to Classes and Objects
Chapter 9: Value-Returning Functions
Objectives In this chapter, you will:
A simple function.
SPL – PS3 C++ Classes.
Presentation transcript:

Programming Perl in UNIX Course Number : CIT 370 Week 6 Prof. Daniel Chen

Introduction n Review and Overviews n Chapters 10 and 11 n Summary n Lab n Next Week (Week 7)

Topics of Discussion n How Do Subroutines Function? n Modularize It, Package It, and Send It to the Library!

Chapter 10: How Do Subroutines function? n Defining and Calling a Subroutine n Passing Arguments n Prototypes n Return Values n Call-by-Reference – Aliases and Typeglobs n Passing by Pointer n Autoloading n BEGIN and END Subroutines (Start and Finish) n The subs Function

Defining and Calling a Subroutine n Subroutine Declaration sub name_of_subroutine; n Subroutine Definition Sub name_of_subroutine { statement; statement;} n Subroutine Call n Subroutine Call with Parameters Example 10.1

Defining and Calling a Subroutine n A Null Parameter List Example 10.2 n Forward Reference Example 10.3 n Scope of Variable Example 10.4

Passing Arguments n Call-by-Reference and Example 10.5 Example 10.6 n Call-by-Value with local and my u The local Function Example 10.7 u The my function Examples10.8 and 10.9 u Using the strict Progma (my and our) Examples and 10.11

Prototypes n A prototype tells the compiler how many and what types of arguments the subroutine should get when it is called. Examples and 12.13

Return Values n The value returned is really the value of the last expression evaluated within the subroutine. Example 10.14

Call-by-Reference – Aliases and Typeglobs n Definition u A typeglob is an alias for a variable. n Passing by Reference with Aliases u Making Aliases private – local versus my Examples and u Passing Filehandles by Reference Example u Select Aliasing and the Backslash Operator Example 10.18

Passing by Pointer n Definition u A hard reference, commonly called a pointer, is a scalar variable that contains the address of another variable. n De-referencing the pointer u Table 10.1 Examples 10.19, 10.20, 10.21, and 10.22

Autoloading n The Perl 5 AUTOLOAD function lets you check to see if a subroutine has been defined. Examples and 10.24

BEGIN and END Subroutines (Start and Finish) n The BEGIN and END subroutines may remind UNIX programmers of the special BEGIN and END patterns used in the awk programming language n The BEGIN has been liked to a constructor, and END a destructor. Example 10.25

The subs Function n The subs function allows you to pre- declare subroutine names. Example 10.26

Chapter 11: Modularize It, Package It, And Send It to the Library! n Packages and Modules n The Standard Perl Library

Packages and Modules n An Analogy n Definition n The Symbol Table

An Analogy n Packages n Symbols (names for variables and constants) n The Ideal: Keeping symbols in their own private packages.

Definition n Encapsulation(Class) n Package(A Separate Namespace) A Separate name space means that Perl has A separate symbol table for all the variables in a named package. n All variables are global within the package. n The package mechanism allows you to switch namespaces, so that variables and subroutines in the package are private. n The scope of the package is from the declaration of the package to the end of the inner most enclosing block, or until another package is declared.

Modules n The extension of packages n A Module (.pm) A package that is usually defined in a library. Modules can export symbols to another packages and to work with classes and methods. n The use function takes the module name as its argument and loads the module into your script.

The Symbol Table n Figure 11.2 – The package provides privacy n Each package has its own symbol table. Any time you use the package declaration, you switch to the symbol table for that package. n A variable assigned using the local function can be accessed in another package by using a scope resolution symbol (::) to qualify it by package name. n The variable assigned using the my function are not accessible outside their own packages.

The examples n Example 11.1 n Example 11.2 n Example 11.3

The Standard Perl Library n Packages and.pl Files u The require Function u Including standard Library Routines Examples: 11.6 and 11.7 u Using Perl to include your own library Example: 11.8 n Modules and.pm Files u The use Function u The Exporter Module F Table 11.1 (Exporting Symbols)

The Standard Perl Library n Using a Perl Module from the Standard Perl Library Examples: 11.9 and n Using Perl to create your own module Example: n Modules from CPAN Example: 11.13

Summary n Defining and Calling a Subroutine n Passing Arguments n Prototypes n Return Values n Call-by-Reference – Aliases and Typeglobs n Passing by Pointer n Autoloading n BEGIN and END Subroutines (Start and Finish) n The subs Function n Modules & Packages

Lab n Examples 10.1 – (P ) n Examples 11-1 – (P 325 – 352) n Homework 6

Next Week n Reading assignment (Textbook chapter 12 and Chapter 16)