Subroutines in Perl. Jon-Michael Deldin. Dept. of Computer Science University of Montana September 12, 2011

Size: px
Start display at page:

Download "Subroutines in Perl. Jon-Michael Deldin. Dept. of Computer Science University of Montana September 12, 2011"

Transcription

1 Subroutines in Perl Jon-Michael Deldin Dept. of Computer Science University of Montana September 12, 2011 Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

2 Outline 1 Overview 2 Elements of a subroutine 3 Example: fasta_to_array 4 Example: clean_fasta Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

3 Topic 1 Overview 2 Elements of a subroutine 3 Example: fasta_to_array 4 Example: clean_fasta Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

4 What is a subroutine? A subroutine is a function in Perl that can take 0 or more arguments. Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

5 Remember these? Functions (Math) f (x) = x 2 + 2x 1 f (3) = 14 Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

6 Remember these? Functions (Perl) Functions (Math) f (x) = x 2 + 2x 1 f (3) = 14 sub f { my $x = shift; return $x**2 + 2*$x - 1; } print "f(3) = ". f(3); Gives us f(3) = 14 Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

7 What can you do with them? Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

8 What can you do with them? Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

9 What can you do with them? Produce reusable code Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

10 What can you do with them? Produce reusable code Make your life easier Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

11 What can you do with them? Produce reusable code Make your life easier Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

12 What can you do with them? Produce reusable code Make your life easier fasta_to_string( sequence.fna ) Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

13 What can you do with them? Produce reusable code Make your life easier fasta_to_string( sequence.fna ) fasta_to_array( sequence.fna ) Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

14 What can you do with them? Produce reusable code Make your life easier fasta_to_string( sequence.fna ) fasta_to_array( sequence.fna ) clean_array(\@array) Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

15 What can you do with them? Produce reusable code Make your life easier fasta_to_string( sequence.fna ) fasta_to_array( sequence.fna ) clean_array(\@array) sequence_genome_and_make_coffee() Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

16 Topic 1 Overview 2 Elements of a subroutine 3 Example: fasta_to_array 4 Example: clean_fasta Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

17 Declaration use the sub keyword assign a name (follows variable naming rules) Example definition sub fasta_to_string { # code goes here } Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

18 Arguments the x in f (x) Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

19 Arguments the x in f (x) as many as you want (even none) Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

20 Arguments the x in f (x) as many as you want (even none) passed in as an array with special Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

21 Arguments the x in f (x) as many as you want (even none) passed in as an array with special scalars only (there s a trick for arrays and hashes) Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

22 Example: Receiving arguments Using shift sub fasta_to_string { # first element my $filename = shift; #... } Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

23 Example: Receiving arguments Using shift sub fasta_to_string { # first element my $filename = shift; #... } sub fasta_to_string { # inline list for vars my ($filename) #... } Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

24 Example: Receiving more than one argument If we needed two arguments, $x, $y, we would get args using multiple shift calls Multiple shift calls sub f { my $x = shift; my $y = shift; #... } Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

25 Example: Receiving more than one argument If we needed two arguments, $x, $y, we would get args using multiple shift calls Multiple shift calls sub f { my $x = shift; my $y = shift; #... } sub f { my ($x, $y) #... } Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

26 Passing an array as an argument You can pass the array like a scalar if only one argument Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

27 Passing an array as an argument You can pass the array like a scalar if only one argument Otherwise, pass the array as a reference (similar to file handles) Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

28 Passing an array as an argument You can pass the array like a scalar if only one argument Otherwise, pass the array as a reference (similar to file handles) When passing an array to a function, use \@my_array as an argument Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

29 Passing an array as an argument You can pass the array like a scalar if only one argument Otherwise, pass the array as a reference (similar to file handles) When passing an array to a function, use \@my_array as an argument When receiving an array in the function, convert back to an array Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

30 Example: Passing arrays as arguments Example sub square_array { my ($arrref) } for (my $i = 0; $i $i++) { $arr[$i] = $arr[$i]**2; } return \@arr; = (0, 1, 2, 3, 4); print "ORIGINAL\n"; print Output ORIGINAL NEW print "\n\nnew\n"; print Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

31 Returning values You can return the result of an operation, but it s not required. Not returning sub f { my $x = shift; print "x was $x!\n"; } prints a value to screen, but unusable Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

32 Returning values You can return the result of an operation, but it s not required. Returning a value Not returning sub f { my $x = shift; print "x was $x!\n"; } prints a value to screen, but unusable sub f { my $x = shift; my $result = $x * rand(10); return $result; } my $num = f(20); print $num; # optional... makes $num this value: Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

33 Topic 1 Overview 2 Elements of a subroutine 3 Example: fasta_to_array 4 Example: clean_fasta Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

34 Planning Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

35 Planning Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

36 Planning fasta_to_array Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

37 Planning fasta_to_array input filename Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

38 Planning fasta_to_array input filename output array Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

39 Planning fasta_to_array input filename output array Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

40 Planning Process fasta_to_array input filename output array Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

41 Planning Process fasta_to_array input filename output array 1 Open a file handle Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

42 Planning Process fasta_to_array input filename output array 1 Open a file handle 2 Read the contents as an array Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

43 Planning Process fasta_to_array input filename output array 1 Open a file handle 2 Read the contents as an array 3 Close the file handle Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

44 Planning Process fasta_to_array input filename output array 1 Open a file handle 2 Read the contents as an array 3 Close the file handle 4 Return the array Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

45 Build the stub Build functions iteratively! Example (sequence.fa) > very interesting sequence ACTG CCCC AAAAAAAA TTTT Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

46 Build the stub Build functions iteratively! function Example (sequence.fa) > very interesting sequence ACTG CCCC AAAAAAAA TTTT use warnings; use strict; sub fasta_to_array { my $filename = shift; } return (); # an empty list for now = fasta_to_array( sequence.fa ); Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

47 Add file handling Code use warnings; use strict; sub fasta_to_array { my $filename = shift; open my $fh, <, $filename or die("can t read $filename"); close $fh; } return (); = fasta_to_array( sequence.fa ); Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

48 Read in the file Code use warnings; use strict; sub fasta_to_array { my $filename = shift; open my $fh, <, $filename or die("can t read $filename"); = <$fh>; close $fh; return \@lines; # a reference } sequence.fa )}; Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

49 Read in the file Code use warnings; use strict; sub fasta_to_array { my $filename = shift; open my $fh, <, $filename or die("can t read $filename"); = <$fh>; close $fh; return \@lines; # a reference } Output > very interesting sequence ACTG CCCC AAAAAAAA TTTT sequence.fa )}; Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

50 Topic 1 Overview 2 Elements of a subroutine 3 Example: fasta_to_array 4 Example: clean_fasta Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

51 Planning Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

52 Planning Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

53 Planning clean_fasta Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

54 Planning clean_fasta input array reference from fasta_to_array Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

55 Planning clean_fasta input array reference from fasta_to_array output array reference Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

56 Planning clean_fasta input array reference from fasta_to_array output array reference Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

57 Planning clean_fasta input array reference from fasta_to_array output array reference Process Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

58 Planning clean_fasta input array reference from fasta_to_array output array reference Process 1 Get the array reference Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

59 Planning clean_fasta input array reference from fasta_to_array output array reference Process 1 Get the array reference 2 Get rid of the header line Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

60 Planning clean_fasta input array reference from fasta_to_array output array reference Process 1 Get the array reference 2 Get rid of the header line 3 For each line, get rid of all whitespace Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

61 Planning clean_fasta input array reference from fasta_to_array output array reference Process 1 Get the array reference 2 Get rid of the header line 3 For each line, get rid of all whitespace 4 Return the cleaned array Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

62 Stub Code sub clean_fasta { my $ref = shift; } return \@arr; sequence.fa ))}; Output > very interesting sequence ACTG CCCC AAAAAAAA TTTT Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

63 Drop the header line Code sub clean_fasta { my $ref = shift; Output } return \@arr; ACTG CCCC AAAAAAAA TTTT sequence.fa ))}; Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

64 Get rid of whitespace Code sub fasta_to_array { my $filename = shift; open my $fh, <, $filename or die("can t read $filename"); = <$fh>; close $fh; } return \@lines; # or a reference, \@lines sub clean_fasta { my $ref = shift; # remove header line Output - ACTG - CCCC - AAAAAAAA - TTTT # get rid of newlines, tabs, spaces for (my $i = 0; $i $i++) { $arr[$i] =~ s/[\t\n ]//g; } } return \@arr; sequence.fa ))}; print "- ". join("\n- Jon-Michael Deldin (UM) Subroutines in Perl September 12, / 24

BLAST. Jon-Michael Deldin. Dept. of Computer Science University of Montana Mon

BLAST. Jon-Michael Deldin. Dept. of Computer Science University of Montana Mon BLAST Jon-Michael Deldin Dept. of Computer Science University of Montana jon-michael.deldin@mso.umt.edu 2011-09-19 Mon Jon-Michael Deldin (UM) BLAST 2011-09-19 Mon 1 / 23 Outline 1 Goals 2 Setting up your

More information

Classnote for COMS6100

Classnote for COMS6100 Classnote for COMS6100 Yiting Wang 3 November, 2016 Today we learn about subroutines, references, anonymous and file I/O in Perl. 1 Subroutines in Perl First of all, we review the subroutines that we had

More information

Subroutines. Subroutines. The Basics. aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc.

Subroutines. Subroutines. The Basics. aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc. Subroutines Subroutines aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc We ll just say Subroutines. "Functions" generally means built-in functions perldoc perlsub The Basics

More information

CS 105 Perl: Perl subroutines and Disciplined Perl

CS 105 Perl: Perl subroutines and Disciplined Perl CS 105 Perl: Perl subroutines and Disciplined Perl Nathan Clement! February 3, 2014 Agenda We will cover Perl scoping, subroutines (user- defined functions) and then we continue on to Perl s features for

More information

Object Oriented Programming and Perl

Object Oriented Programming and Perl Object Oriented Programming and Perl Prog for Biol 2011 Simon Prochnik 1 Why do we teach you about objects and object-oriented programming (OOP)? Objects and OOP allow you to use other people s code to

More information

Introduction to Perl Session 6. special variables subroutines Introduction to Perl

Introduction to Perl Session 6. special variables subroutines Introduction to Perl 1.0.1.8.6 Introduction to Perl Session 6 special variables subroutines 6/17/2008 1.0.1.8.6 - Introduction to Perl - Special Variables and Subroutines 1 I/O Recap file handles are created using open(f,$file);

More information

Perl for Biologists. Session 9 April 29, Subroutines and functions. Jaroslaw Pillardy

Perl for Biologists. Session 9 April 29, Subroutines and functions. Jaroslaw Pillardy Perl for Biologists Session 9 April 29, 2015 Subroutines and functions Jaroslaw Pillardy Perl for Biologists 1.2 1 Suggestions Welcomed! There are three more sessions devoted to practical examples They

More information

Perl Library Functions

Perl Library Functions Perl Library Functions Perl has literally hundreds of functions for all kinds of purposes: file manipulation, database access, network programming, etc. etc. It has an especially rich collection of functions

More information

COMS 3101 Programming Languages: Perl. Lecture 5

COMS 3101 Programming Languages: Perl. Lecture 5 COMS 3101 Programming Languages: Perl Lecture 5 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Packages & Modules Concepts: Subroutine references Symbolic

More information

IT441. Subroutines. (a.k.a., Functions, Methods, etc.) DRAFT. Network Services Administration

IT441. Subroutines. (a.k.a., Functions, Methods, etc.) DRAFT. Network Services Administration IT441 Network Services Administration Subroutines DRAFT (a.k.a., Functions, Methods, etc.) Organizing Code We have recently discussed the topic of organizing data (i.e., arrays and hashes) in order to

More information

Perl for Biologists. Object Oriented Programming and BioPERL. Session 10 May 14, Jaroslaw Pillardy

Perl for Biologists. Object Oriented Programming and BioPERL. Session 10 May 14, Jaroslaw Pillardy Perl for Biologists Session 10 May 14, 2014 Object Oriented Programming and BioPERL Jaroslaw Pillardy Perl for Biologists 1.1 1 Subroutine can be declared in Perl script as a named block of code: sub sub_name

More information

BIOS 546 Midterm March 26, Write the line of code that all Perl programs on biolinx must start with so they can be executed.

BIOS 546 Midterm March 26, Write the line of code that all Perl programs on biolinx must start with so they can be executed. 1. What values are false in Perl? BIOS 546 Midterm March 26, 2007 2. Write the line of code that all Perl programs on biolinx must start with so they can be executed. 3. How do you make a comment in Perl?

More information

Arrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff

Arrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff and Arrays Comp Sci 1570 Introduction to C++ Outline and 1 2 Multi-dimensional and 3 4 5 Outline and 1 2 Multi-dimensional and 3 4 5 Array declaration and An array is a series of elements of the same type

More information

More Perl. CS174 Chris Pollett Oct 25, 2006.

More Perl. CS174 Chris Pollett Oct 25, 2006. More Perl CS174 Chris Pollett Oct 25, 2006. Outline Loops Arrays Hashes Functions Selection Redux Last day we learned about how if-else works in Perl. Perl does not have a switch statement Like Javascript,

More information

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body;

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body; CLASSROOM SESSION Loops in C Loops are used to repeat the execution of statement or blocks There are two types of loops 1.Entry Controlled For and While 2. Exit Controlled Do while FOR Loop FOR Loop has

More information

Computer Programming: C++

Computer Programming: C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #7 Arrays Part II Passing Array to a Function

More information

COMS 3101 Programming Languages: Perl. Lecture 6

COMS 3101 Programming Languages: Perl. Lecture 6 COMS 3101 Programming Languages: Perl Lecture 6 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Concepts: Subroutine references Symbolic references Saving

More information

Using References to Create Complex Structures. The array and hash composers

Using References to Create Complex Structures. The array and hash composers Using References to Create Complex Structures The array and hash composers Copyright 2006 2009 Stewart Weiss Anonymous array composer You can create a hard reference to an anonymous array using square

More information

Outline. CS3157: Advanced Programming. Feedback from last class. Last plug

Outline. CS3157: Advanced Programming. Feedback from last class. Last plug Outline CS3157: Advanced Programming Lecture #2 Jan 23 Shlomo Hershkop shlomo@cs.columbia.edu Feedback Introduction to Perl review and continued Intro to Regular expressions Reading Programming Perl pg

More information

Systems Skills in C and Unix

Systems Skills in C and Unix 15-123 Systems Skills in C and Unix Plan Perl programming basics Operators loops, arrays, conditionals file processing subroutines, references Systems programming Command line arguments Perl intro Unix

More information

CS 230 Programming Languages

CS 230 Programming Languages CS 230 Programming Languages 09 / 16 / 2013 Instructor: Michael Eckmann Today s Topics Questions/comments? Continue Syntax & Semantics Mini-pascal Attribute Grammars More Perl A more complex grammar Let's

More information

Linked Memory. Pointers Linked Lists. September 21, 2017 Cinda Heeren / Geoffrey Tien 1

Linked Memory. Pointers Linked Lists. September 21, 2017 Cinda Heeren / Geoffrey Tien 1 Linked Memory Pointers Linked Lists September 21, 2017 Cinda Heeren / Geoffrey Tien 1 Releasing Dynamic Memory When a function call is complete its stack memory is released and can be re-used Dynamic memory

More information

Control Structures. Important Semantic Difference

Control Structures. Important Semantic Difference Control Structures Important Semantic Difference In all of these loops we are going to discuss, the braces are ALWAYS REQUIRED. Even if your loop/block only has one statement, you must include the braces.

More information

16.216: ECE Application Programming Spring 2015 Exam 2 Solution

16.216: ECE Application Programming Spring 2015 Exam 2 Solution 16.216: ECE Application Programming Spring 2015 Exam 2 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II CS313D: ADVANCED PROGRAMMING LANGUAGE Lecture 3: C# language basics II Lecture Contents 2 C# basics Methods Arrays Methods 3 A method: groups a sequence of statement takes input, performs actions, and

More information

PERL Scripting - Course Contents

PERL Scripting - Course Contents PERL Scripting - Course Contents Day - 1 Introduction to PERL Comments Reading from Standard Input Writing to Standard Output Scalar Variables Numbers and Strings Use of Single Quotes and Double Quotes

More information

Perl and Python ESA 2007/2008. Eelco Schatborn 27 September 2007

Perl and Python ESA 2007/2008. Eelco Schatborn 27 September 2007 Perl and Python ESA 2007/2008 Eelco Schatborn eelco@os3.nl 27 September 2007 ESA: Perl Vandaag: 1. Perl introduction 2. Basic Perl: types, variables, statements,... 3. Object Oriented Perl 4. Documentation

More information

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17 CS313D: ADVANCED PROGRAMMING LANGUAGE Lecture 3: C# language basics II Lecture Contents 2 C# basics Methods Arrays 1 Methods : Method Declaration: Header 3 A method declaration begins with a method header

More information

Shells & Shell Programming (Part B)

Shells & Shell Programming (Part B) Shells & Shell Programming (Part B) Software Tools EECS2031 Winter 2018 Manos Papagelis Thanks to Karen Reid and Alan J Rosenthal for material in these slides CONTROL STATEMENTS 2 Control Statements Conditional

More information

Higher Order Perl. Finlay Thompson. 14 March 2006

Higher Order Perl. Finlay Thompson. 14 March 2006 Finlay Thompson 14 March 2006 Talk Outline What is this all about? Some FP techniques and ideas Loops, recursion, iterators, chasing tails, loops Currying and anonymous subroutines Conclusions What is

More information

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain Duhok Polytechnic University Amedi Technical Institute/ IT Dept. By Halkawt Rajab Hussain 2016-04-02 Pointers: Pointer declaration and initialization. Pointer To Pointer. Arithmetic operation on pointer

More information

A QUICK OVERVIEW OF THE OMNeT++ IDE

A QUICK OVERVIEW OF THE OMNeT++ IDE Introduction A QUICK OVERVIEW OF THE OMNeT++ IDE The OMNeT++ Integrated Development Environment is based on the Eclipse platform, and extends it with new editors, views, wizards, and additional functionality.

More information

Linked Memory. Pointers Linked Lists. January 19, 2018 Cinda Heeren / Geoffrey Tien 1

Linked Memory. Pointers Linked Lists. January 19, 2018 Cinda Heeren / Geoffrey Tien 1 Linked Memory Pointers Linked Lists January 19, 2018 Cinda Heeren / Geoffrey Tien 1 Addresses and pointers Every storage location in memory (RAM) has an address associated with it The address is the location

More information

Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10

Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10 Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10 Ziad Matni Dept. of Computer Science, UCSB Lecture Outline Useful character manipulators & functions

More information

Functions. Lecture 6 COP 3014 Spring February 11, 2018

Functions. Lecture 6 COP 3014 Spring February 11, 2018 Functions Lecture 6 COP 3014 Spring 2018 February 11, 2018 Functions A function is a reusable portion of a program, sometimes called a procedure or subroutine. Like a mini-program (or subprogram) in its

More information

COMP1917: 09 Arrays and Strings

COMP1917: 09 Arrays and Strings COMP1917: 09 Arrays and Strings Sim Mautner s.mautner@unsw.edu.au August 15, 2016 Sim Mautner (UNSW) COMP1917: 09 Arrays and Strings August 15, 2016 1 / 14 Arrays int sum(int n1, int n2); int sum(int n1,

More information

Cpt S 122 Data Structures. Introduction to C++ Part II

Cpt S 122 Data Structures. Introduction to C++ Part II Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function

More information

Outline. CS3157: Advanced Programming. Feedback from last class. Announcement

Outline. CS3157: Advanced Programming. Feedback from last class. Announcement Outline CS3157: Advanced Programming Lecture #3 Jan 25 Shlomo Hershkop shlomo@cs.columbia.edu Feedback More Regular Expressions Scope Hashing File handling II Complex examples Reading: Chapter 4,5 (pg-167)

More information

VLC : Language Reference Manual

VLC : Language Reference Manual VLC : Language Reference Manual Table Of Contents 1. Introduction 2. Types and Declarations 2a. Primitives 2b. Non-primitives - Strings - Arrays 3. Lexical conventions 3a. Whitespace 3b. Comments 3c. Identifiers

More information

perl -MO=Deparse[,-d][,-fFILE][,-p][,-q][,-l] [,-sletters][,-xlevel] prog.pl

perl -MO=Deparse[,-d][,-fFILE][,-p][,-q][,-l] [,-sletters][,-xlevel] prog.pl NAME SYNOPSIS DESCRIPTION OPTIONS B::Deparse - Perl compiler backend to produce perl code perl -MO=Deparse[,-d][,-fFILE][,-p][,-q][,-l] [,-sletters][,-xlevel] prog.pl B::Deparse is a backend module for

More information

Perl Programming Fundamentals for the Computational Biologist

Perl Programming Fundamentals for the Computational Biologist Perl Programming Fundamentals for the Computational Biologist Class 2 Marine Biological Laboratory, Woods Hole Advances in Genome Technology and Bioinformatics Fall 2004 Andrew Tolonen Chisholm lab, MIT

More information

IN CHAPTER 7, SUBROUTINES AND MODULES, you learned how to organize

IN CHAPTER 7, SUBROUTINES AND MODULES, you learned how to organize 8 Object-Oriented Programming IN CHAPTER 7, SUBROUTINES AND MODULES, you learned how to organize your code into subroutines, packages, and modules. In this chapter, you ll find out how to create objects

More information

Perl. Interview Questions and Answers

Perl. Interview Questions and Answers and Answers Prepared by Abhisek Vyas Document Version 1.0 Team, www.sybaseblog.com 1 of 13 Q. How do you separate executable statements in perl? semi-colons separate executable statements Example: my(

More information

Learning Perl 6. brian d foy, Version 0.6, Nordic Perl Workshop 2007

Learning Perl 6. brian d foy, Version 0.6, Nordic Perl Workshop 2007 Learning Perl 6 brian d foy, Version 0.6, Nordic Perl Workshop 2007 for the purposes of this tutorial Perl 5 never existed Don t really do this $ ln -s /usr/local/bin/pugs /usr/bin/perl

More information

Introduction to C Programming

Introduction to C Programming 1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print

More information

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

BIFS 617 Dr. Alkharouf. Topics. Parsing GenBank Files. More regular expression modifiers. /m /s

BIFS 617 Dr. Alkharouf. Topics. Parsing GenBank Files. More regular expression modifiers. /m /s Parsing GenBank Files BIFS 617 Dr. Alkharouf 1 Parsing GenBank Files Topics More regular expression modifiers /m /s 2 1 Parsing GenBank Libraries Parsing = systematically taking apart some unstructured

More information

Object-Oriented-Programming! (OOP)

Object-Oriented-Programming! (OOP) Object-Oriented-Programming! (OOP) Basically it s all about abstraction & information hiding n Good programs consist of layer upon layer of reusable code (think of software tools). n The programmer should

More information

TableGen. Language Reference Manual

TableGen. Language Reference Manual TableGen Language Reference Manual Andrey Falko (asf2125) Daniel Pestov (dp2297) Del Slane (djs2160) Timothy Washington (tw2212) October 18, 2007 1. Introduction TableGen is an interpreted programming

More information

COMS 3101 Programming Languages: Perl. Lecture 2

COMS 3101 Programming Languages: Perl. Lecture 2 COMS 3101 Programming Languages: Perl Lecture 2 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Control Flow (continued) Input / Output Subroutines Concepts:

More information

The Perl Debugger. Avoiding Bugs with Warnings and Strict. Daniel Allen. Abstract

The Perl Debugger. Avoiding Bugs with Warnings and Strict. Daniel Allen. Abstract 1 of 8 6/18/2006 7:36 PM The Perl Debugger Daniel Allen Abstract Sticking in extra print statements is one way to debug your Perl code, but a full-featured debugger can give you more information. Debugging

More information

Functions. Arash Rafiey. September 26, 2017

Functions. Arash Rafiey. September 26, 2017 September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic

More information

8. Random Number Generation

8. Random Number Generation 8. Random Number Generation Pseudo-Random Numbers To simulate noise signals in the real world (true random numbers) e.g., background ambient noise in acoustics; turbulence in fluid flows To generate values

More information

1 Apache2::Directive - Perl API for manipulating the Apache configuration tree

1 Apache2::Directive - Perl API for manipulating the Apache configuration tree Apache2::Directive - Perl API for manipulating the Apache configuration tree 1 Apache2::Directive - Perl API for manipulating the Apache configuration tree 1 Apache2::Directive - Perl API for manipulating

More information

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi Titolo presentazione Piattaforme Software per la Rete sottotitolo BASH Scripting Milano, XX mese 20XX A.A. 2016/17, Alessandro Barenghi Outline 1) Introduction to BASH 2) Helper commands 3) Control Flow

More information

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts COMP519 Web Programming Lecture 20: Python (Part 4) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

More information

Figure 1 Common Sub Expression Optimization Example

Figure 1 Common Sub Expression Optimization Example General Code Optimization Techniques Wesley Myers wesley.y.myers@gmail.com Introduction General Code Optimization Techniques Normally, programmers do not always think of hand optimizing code. Most programmers

More information

Introduction to Programming I COS1511 School of Computing Revision Notes

Introduction to Programming I COS1511 School of Computing Revision Notes Introduction to Programming I COS1511 School of Computing Revision Notes UNISA 2018 1 Introduction Some key basic principles to remember: Apply the BODMAS rules of Mathematics for all calculations; The

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 9/11/2013 Textual data processing (Perl) 1 Announcements If you did not get a PIN to enroll, contact Stephanie Meik 2 Outline Perl Basics (continued) Regular Expressions

More information

IT441. Network Services Administration. Data Structures: Arrays

IT441. Network Services Administration. Data Structures: Arrays IT441 Network Services Administration Data Structures: Arrays Data Types Remember there are three basic data types in Perl o Numeric o String o Boolean (Logical) I differentiate between data types and

More information

Modularity and Reusability I. Functions and code reuse

Modularity and Reusability I. Functions and code reuse Modularity and Reusability I Functions and code reuse Copyright 2006 2009 Stewart Weiss On being efficient When you realize that a piece of Perl code that you wrote may be useful in future programs, you

More information

QTP Open Source Test Automation Framework Coding Standards for Developers

QTP Open Source Test Automation Framework Coding Standards for Developers Coding Standards for Developers Version 1.0 April 2009 D ISCLAIMER Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice

More information

This document describes version 0.87 of Attribute::Handlers, released September 21, 2009.

This document describes version 0.87 of Attribute::Handlers, released September 21, 2009. NAME VERSION SYNOPSIS Attribute::Handlers - Simpler definition of attribute handlers This document describes version 0.87 of Attribute::Handlers, released September 21, 2009. package MyClass; require 5.006;

More information

Choose 3 of the 1 st 4 questions (#'s 1 through 4) to complete. Each question is worth 12 points.

Choose 3 of the 1 st 4 questions (#'s 1 through 4) to complete. Each question is worth 12 points. Choose 3 of the 1 st 4 questions (#'s 1 through 4) to complete. Each question is worth 12 points. Use the remaining question as extra credit (worth 1/2 of the points earned). Specify which question is

More information

perl -MO=Deparse[,-d][,-fFILE][,-p][,-q][,-l] [,-sletters][,-xlevel] prog.pl

perl -MO=Deparse[,-d][,-fFILE][,-p][,-q][,-l] [,-sletters][,-xlevel] prog.pl NAME SYNOPSIS DESCRIPTION OPTIONS B::Deparse - Perl compiler backend to produce perl code perl -MO=Deparse[,-d][,-fFILE][,-p][,-q][,-l] [,-sletters][,-xlevel] prog.pl B::Deparse is a backend module for

More information

Functions. Systems Programming Concepts

Functions. Systems Programming Concepts Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Functional Programming Robert Rand University of Pennsylvania February 03, 2016 Robert Rand (University of Pennsylvania) CIS 192 February 03, 2016 1 / 23 Outline 1 Function Arguments

More information

CSCE 121 ENGR 112 List of Topics for Exam 1

CSCE 121 ENGR 112 List of Topics for Exam 1 List of Topics for Exam 1 If statements o How is an if statement constructed? o Does every if need an else? Looping o While loop! What does a while loop look like?! How do you ensure you will not have

More information

SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7

SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7 SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7 Hi everyone once again welcome to this lecture we are actually the course is Linux programming and scripting we have been talking about the Perl, Perl

More information

Procedures. EOPL3: Section 3.3 PROC and App B: SLLGEN

Procedures. EOPL3: Section 3.3 PROC and App B: SLLGEN Procedures EOPL3: Section 3.3 PROC and App B: SLLGEN The PROC language Expression ::= proc (Identifier) Expression AST: proc-exp (var body) Expression ::= (Expression Expression) AST: call-exp (rator rand)

More information

Statement Basics. Assignment Statements

Statement Basics. Assignment Statements Statement Basics The meaning of a single statement executed in a state s is a new state s, which reflects the effects of the statement M stmt ( stmt, s) = s N. Meng, S. Arthur 1 Assignment Statements M

More information

Teaching guide: Subroutines

Teaching guide: Subroutines Teaching guide: Subroutines This resource will help with understanding subroutines. It supports Sections 3.2.2 and 3.2.10 of our current GCSE Computer Science specification (8520). The guide is designed

More information

Chapter 4. Programming in Perl. 4.1 More on built-in functions in Perl split and join (+ qw, x operator, here docs,.=)

Chapter 4. Programming in Perl. 4.1 More on built-in functions in Perl split and join (+ qw, x operator, here docs,.=) Chapter 4 Programming in Perl 4.1 More on built-in functions in Perl There are many built-in functions in Perl, and even more are available as modules (see section 4.4) that can be downloaded from various

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

TIPS AND TRICKS: IMPROVE EFFICIENCY TO YOUR SAS PROGRAMMING

TIPS AND TRICKS: IMPROVE EFFICIENCY TO YOUR SAS PROGRAMMING TIPS AND TRICKS: IMPROVE EFFICIENCY TO YOUR SAS PROGRAMMING Guillaume Colley, Lead Data Analyst, BCCFE Page 1 Contents Customized SAS Session Run system options as SAS starts Labels management Shortcut

More information

Shell Programming (bash)

Shell Programming (bash) Shell Programming Shell Programming (bash) Commands run from a file in a subshell A great way to automate a repeated sequence of commands. File starts with #!/bin/bash absolute path to the shell program

More information

Script Programming Systems Skills in C and Unix

Script Programming Systems Skills in C and Unix Script Programming with Perl II 15-123 Systems Skills in C and Unix Subroutines sub sum { return $a + $b; } So we can call this as: $a = 12; $b = 10; $sum = sum(); print the sum is $sum\n ; Passing Arguments

More information

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 4 Database Programming PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL) AGENDA 6. Stored Functions Procedural Database Programming

More information

Chapter 1. Section 1.4 Subprograms or functions. CS 50 - Hathairat Rattanasook

Chapter 1. Section 1.4 Subprograms or functions. CS 50 - Hathairat Rattanasook Chapter 1 Section 1.4 Subprograms or functions 0 Functions Functions are essential in writing structured and well-organized code. Functions help for code to be reused. Functions help to reduce errors and

More information

Introduction to Fortran Programming. -Internal subprograms (1)-

Introduction to Fortran Programming. -Internal subprograms (1)- Introduction to Fortran Programming -Internal subprograms (1)- Subprograms Subprograms are used to split the program into separate smaller units. Internal subprogram is not an independent part of a program.

More information

Office 2016 Excel Basics 06 Video/Class Project #18 Excel Basics 6: Customize Quick Access Toolbar (QAT) and Show New Ribbon Tabs

Office 2016 Excel Basics 06 Video/Class Project #18 Excel Basics 6: Customize Quick Access Toolbar (QAT) and Show New Ribbon Tabs **These pdf Notes are for video 6-8. Scroll down to see notes for all three videos. Office 2016 Excel Basics 06 Video/Class Project #18 Excel Basics 6: Customize Quick Access Toolbar (QAT) and Show New

More information

11/29/17. Outline. Subprograms. Subroutine. Subroutine. Parameters. Characteristics of Subroutines/ Subprograms

11/29/17. Outline. Subprograms. Subroutine. Subroutine. Parameters. Characteristics of Subroutines/ Subprograms Outline Subprograms In Text: Chapter 9 Definitions Design issues for subroutines Parameter passing modes and mechanisms Advanced subroutine issues N. Meng, S. Arthur 2 Subroutine A sequence of program

More information

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295 Perl Scripting Duration: 4 Days Price: $2295 Discounts: We offer multiple discount options. Click here for more info. Delivery Options: Attend face-to-face in the classroom, remote-live or on-demand streaming.

More information

Perl One-Liners by Peteris Krumins

Perl One-Liners by Peteris Krumins 1 Introduction to Perl one-liners are small and awesome Perl programs that fit in a single line of code. They do one thing really well like changing line spacing, numbering lines, performing calculations,

More information

Regular expressions and case insensitivity

Regular expressions and case insensitivity Regular expressions and case insensitivity As previously mentioned, you can make matching case insensitive with the i flag: /\b[uu][nn][ii][xx]\b/; # explicitly giving case folding /\bunix\b/i; # using

More information

Homework 4: Hash Tables Due: 5:00 PM, Mar 9, 2018

Homework 4: Hash Tables Due: 5:00 PM, Mar 9, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Homework 4: Hash Tables Due: 5:00 PM, Mar 9, 2018 1 DIY Grep 2 2 Chaining Hash Tables 4 3 Hash Table Iterator 5 Objectives By the

More information

Normal Order (Lazy) Evaluation SICP. Applicative Order vs. Normal (Lazy) Order. Applicative vs. Normal? How can we implement lazy evaluation?

Normal Order (Lazy) Evaluation SICP. Applicative Order vs. Normal (Lazy) Order. Applicative vs. Normal? How can we implement lazy evaluation? Normal Order (Lazy) Evaluation Alternative models for computation: Normal (Lazy) Order Evaluation Memoization Streams Applicative Order: evaluate all arguments, then apply operator Normal Order: pass unevaluated

More information

Data::Dumper - stringified perl data structures, suitable for both printing and eval

Data::Dumper - stringified perl data structures, suitable for both printing and eval NAME SYNOPSIS Data::Dumper - stringified perl data structures, suitable for both printing and eval use Data::Dumper; # simple procedural interface print Dumper($foo, $bar); # extended usage with names

More information

Awk. 1 What is AWK? 2 Why use AWK instead of Perl? 3 Uses Of AWK. 4 Basic Structure Of AWK Programs. 5 Running AWK programs

Awk. 1 What is AWK? 2 Why use AWK instead of Perl? 3 Uses Of AWK. 4 Basic Structure Of AWK Programs. 5 Running AWK programs Awk Author: Reuben Francis Cornel 1 What is AWK? AWK is a programable filter developed with the aim of using it to generate formatted reports from data. Althought is uses addresses like sed to perform

More information

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE HEADER FILE A header (.h,.hpp,...) file contains Class definitions ( class X {... }; ) Inline function definitions ( inline int get_x() {... } ) Function declarations ( void help(); ) Object declarations

More information

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Control

More information

Lecture 18 Tao Wang 1

Lecture 18 Tao Wang 1 Lecture 18 Tao Wang 1 Abstract Data Types in C++ (Classes) A procedural program consists of one or more algorithms that have been written in computerreadable language Input and display of program output

More information

IBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition?

IBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition? IBS Software Services Technical Interview Questions Q1. What is the difference between declaration and definition? The declaration tells the compiler that at some later point we plan to present the definition

More information

Lecture 04 FUNCTIONS AND ARRAYS

Lecture 04 FUNCTIONS AND ARRAYS Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions

More information

CS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College September 13, 2018

CS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College September 13, 2018 CS 31: Intro to Systems C Programming Kevin Webb Swarthmore College September 13, 2018 Reading Quiz Agenda Basics of C programming Comments, variables, print statements, loops, conditionals, etc. NOT the

More information

package YourModule; require = = qw(munge frobnicate); # symbols to export on request

package YourModule; require = = qw(munge frobnicate); # symbols to export on request NAME SYNOPSIS Exporter - Implements default import method for modules In module YourModule.pm: require Exporter; @EXPORT_OK = qw(munge frobnicate); # symbols to export on request or use Exporter 'import';

More information

Perl Tutorial. Diana Inkpen. School of Information Technology and Engineering University of Ottawa. CSI 5180, Fall 2004

Perl Tutorial. Diana Inkpen. School of Information Technology and Engineering University of Ottawa. CSI 5180, Fall 2004 Perl Tutorial Diana Inkpen School of Information Technology and Engineering University of Ottawa CSI 5180, Fall 2004 1 What is Perl Practical Extraction and Report Language. Created, implemented, maintained

More information

DelphiScript Keywords

DelphiScript Keywords DelphiScript Keywords Old Content - visit altium.com/documentation Modified by on 13-Sep-2017 This reference covers the DelphiScript keywords used for the Scripting System in Altium Designer. The scripting

More information

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7) Array Basics: Outline Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and Constants

More information