Prof. Alfred J Bird, Ph.D., NBCT Office – McCormack 3rd floor 607.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
Advertisements

Spring Semester 2013 Lecture 5
Objectives Using functions to organize PHP code
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
CS 330 Programming Languages 10 / 14 / 2008 Instructor: Michael Eckmann.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
CS 330 Programming Languages 10 / 11 / 2007 Instructor: Michael Eckmann.
CS 330 Programming Languages 09 / 30 / 2008 Instructor: Michael Eckmann.
Scripting Languages Perl Chapter #4 Subroutines. Writing your own Functions Functions is a programming language serve tow purposes: –They allow you to.
Parameters, Arguments, Local Variables, and Scope CSC 1401: Introduction to Programming with Java Week 8 – Lecture 1 Wanda M. Kunkle.
Introduction to Methods
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Prof. Alfred J Bird, Ph.D., NBCT Office – Wheatly 2nd floor Office Hours – MW 3:00PM to 4:00PM.
Subroutines Just like C, PERL offers the ability to use subroutines for all the same reasons – Code that you will use over and over again – Breaking large.
Prof. Alfred J Bird, Ph.D., NBCT Office – Wheatly 2nd floor Office Hours – MW 3:00PM.
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students – * Office – Wheatly.
 2005 Pearson Education, Inc. All rights reserved. 1 Methods Called functions or procedures in other languages Modularize programs by separating its tasks.
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
Prof. Alfred J Bird, Ph.D., NBCT Door Code: * Office – McCormick 3rd floor 607 Office.
1 SystemVerilog Enhancement Requests Daniel Schostak Principal Engineer February 26 th 2010.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Prof. Alfred J Bird, Ph.D., NBCT -bird.wikispaces.umb.edu/ Office – McCormick 3rd floor.
CS 330 Programming Languages 10 / 07 / 2008 Instructor: Michael Eckmann.
Chapter Function Basics CSC1310 Fall Function function (subroutine, procedure)a set of statements different inputs (parameters) outputs In.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
Programming Perl in UNIX Course Number : CIT 370 Week 6 Prof. Daniel Chen.
Julian on JavaScript: Functions Julian M Bucknall, CTO.
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.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.
Function Basics. Function In this chapter, we will move on to explore a set of additional statements that create functions of our own function (subroutine,
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
Unit 10-JavaScript Functions Instructor: Brent Presley.
MIT-AITI: Functions Defining and Invoking Functions Functions as Data Function Scope: The call Object Function Arguments: The arguments objects Function.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
CSIS 113A Lecture 5 Functions. Introduction to Functions  Building Blocks of Programs  Other terminology in other languages:  Procedures, subprograms,
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3nd floor, room 607 Office Hours –Tuesday.
 The real power of PHP comes from its functions; it has more than 1000 built-in functions.  PHP User Defined Functions  Besides the built-in PHP functions,
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.
Lecture 9: Basic concepts of Perl Modules. Functions (Subs) In perl functions take the following format: – sub subname – { my $var1 = $_[0]; statements.
Data Type and Function Prepared for CSB210 Pemrograman Berorientasi Objek By Indriani Noor Hapsari, ST, MT Source: study.
IT441 Network Services Administration
IT441 Network Services Administration
JavaScript: Functions
Perl Modules.
Subroutines Web Programming.
Passing Parameters by value
Perl Functions.
CSCI 431 Programming Languages Fall 2003
Chapter 7: Using Functions, Subs, and Modules
Parameters and Arguments
Presentation transcript:

Prof. Alfred J Bird, Ph.D., NBCT Office – McCormack 3rd floor 607 Office Hours – Tuesday and Thursday 4:00PM to 5:15PM

 What is a subroutine?  How is it different from a function?  Why do we use subroutines?

 Subroutines in Perl have three parts:  The declaration sub  The name of the subroutine  The name may contain a list of parameters  Make the name mean something to you  A block of code enclosed in curly braces { actions }  The subroutine can contain any code that the main routine can contain. It can even call other subroutines.

 The most common way is to just refer to it by its name followed by a set of parentheses ( ) exampleSubroutine()  This can call a subroutine defined anywhere in the file.  If the subroutine is defined prior to its invocation the parenthesis can be omitted. exampleSubroutine

 We can also invoke the subroutine before is is defines if we let the code know it is a subroutine. We can do the by:  By including the statement sub exampleSubroutine; prior to invoking it  Or calling it by &exampleSubroutine;  You can think of the & as a type declaration sort of like and %  The first method is the more common

 Arguments (parameters) can be passed into the subroutine inside an array in parenthesis following the name.  Arguments are passed by reference, not by name or value  Arguments are passed in the  You should not use the directly but should assign it to another array ;

 Subroutines return a value. It is the result of the last assignment completed. my $value = exampleSubroutine();  You can use a return statement in a subroutine  As soon as the first return statement is reached, control is returned to the calling program.

 There are two main types of variables.  Global or package variables:  Global variables are accessible anywhere in the program  Lexical or local variables  Only accessible within the block of code where they are defined  Defined with a my statement  Why do we have two types of variables?  All variables are global by default!

 What is a namespace?  What is a package?  Packages are perl files with.pm extn and are considered a separate namespace. So a package is nothing but group of related scalars,arrays,hashes and subroutines for a specific purpose. Once a package is included in a.pl file (using "use") and you want to call one of the subroutines of the package, you may have to use the scope resolution operator &package::subroutine1

 What is a module?  Modules are packages which have the capabilities of exporting selective subroutines/scalars/arrays/hashes of the package to the namespace of the main package itself. So for the interpreter these look as though the subroutines are part of the main package itself and so there is no need to use the scope resolution operator while calling them.

 Why use PERL?\  What other languages could we use?  Ruby, Python, Scripting…..  TIMTOWTDI!!  Other people have already done it!   

 In the book “Beginning Perl”  Read and understand pages  Read pages 215 – 229  In the book “Beginning Ubuntu Server”  Read pages