How to write & use Perl Modules. What is a Module? A separate Namespace in a separate file with related functions/variables.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
Advertisements

Mod_perl High speed dynamic content. Definitions Apache – OpenSource httpd server Perl – OpenSource interpreted programming language mod_perl – OpenSource.
Arrays A list is an ordered collection of scalars. An array is a variable that holds a list. Arrays have a minimum size of 0 and a very large maximum size.
05/11/2001 CPT week Natalia Ratnikova, FNAL 1 Software Distribution in CMS Distribution unitFormContent Version of SCRAM managed project.
Advanced Perl WUC Perl Poetry Variable Scope.
Chapter Modules CSC1310 Fall Modules Modules Modules are the highest level program organization unit, usually correspond to source files and.
Lecture 6 More advanced Perl…. Substitute Like s/// function in vi: #cut with EcoRI and chew back $linker = “GGCCAATTGGAAT”; $linker =~ s/CAATTG/CG/g;
Objected Oriented Perl An introduction – because I don’t have the time or patience for an in- depth OOP lecture series…
Computer Programming for Biologists Class 9 Dec 4 th, 2014 Karsten Hokamp
12.1 בשבועות הקרובים יתקיים סקר ההוראה (באתר מידע אישי לתלמיד)באתר מידע אישי לתלמיד סקר הוראה.
CS 330 Programming Languages 10 / 14 / 2008 Instructor: Michael Eckmann.
CS 330 Programming Languages 10 / 11 / 2007 Instructor: Michael Eckmann.
11ex.1 Modules and BioPerl. 11ex.2 sub reverseComplement { my ($seq) $seq =~ tr/ACGT/TGCA/; $seq = reverse $seq; return $seq; } my $revSeq = reverseComplement("GCAGTG");
Scripting Languages Perl Chapter #4 Subroutines. Writing your own Functions Functions is a programming language serve tow purposes: –They allow you to.
1 Chapter 8 Designing Small Programs. 2 A ‘Procedure’ v A set of instructions which describe the steps to be followed in order to carry out an activity.
10.1 Sorting and Modules בשבועות הקרובים יתקיים סקר ההוראה (באתר מידע אישי לתלמיד)באתר מידע אישי לתלמיד סקר הוראה.
1 Writing Perl 5 Modules: An Introduction Keith Arner.
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
CSE S. Tanimoto Perl Arrays, Functions, Lists, Refs, Etc 1 Perl: Arrays, Functions, References, Etc. Arrays Slices, splices Contexts: list, scalar.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Lecture 8: Basic concepts of subroutines. Functions In perl functions take the following format: – sub subname – { my $var1 = $_[0]; statements Return.
– Intermediate Perl 8/27/ Intermediate Perl - modules Intermediate Perl – Session 5 · modules · CPAN.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Access Control Problem A primary consideration in object- oriented design is to “separate the things that change from the things that stay.
July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormack 3rd floor 607.
Introduction to Python 2 Dr. Bernard Chen University of Central Arkansas PyArkansas 2011.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Subroutines and Files Bioinformatics Ellen Walker Hiram College.
Compiled Matlab on Condor: a recipe 30 th October 2007 Clare Giacomantonio.
13.1 בשבועות הקרובים יתקיים סקר ההוראה (באתר מידע אישי לתלמיד)באתר מידע אישי לתלמיד סקר הוראה.
1 Using Modules. 2 Modules A Perl module is a collection of subroutines and variables that typically implements some common functionality – and "packaged"
Beginning BioPerl for Biologists MPI Ploen Jun Wang.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to Perl Yupu Liang cbio at MSKCC
How to create and install packages in R Presenter: Roman Jandarov
Programming Perl in UNIX Course Number : CIT 370 Week 6 Prof. Daniel Chen.
Warming up to modular testing Raleigh.pm Brad Oaks of Plus Three, LP.
Computer Programming for Biologists Class 6 Nov 21 th, 2014 Karsten Hokamp
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Executable scripts. So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory?
March 21, 2003 Fabrizio Coccetti - Stanford Linear Accelerator Center1 How to write Perl Modules Some practical advice about how to build a perl module.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Separate Compilation and Namespaces.
Chapter 15. Modules Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Intro to Object Oriented Perl Packages, Modules, Classes.
CS 368 – Intro to Scripting Languages Summer 2009 Cartwright, De Smet, LeRoy Object Oriented Programming Programming Perl Chapter 12: "Objects"
Software Design– Unit Testing SIMPLE PRIMER ON Junit Junit is a free simple library that is added to Eclipse to all automated unit tests. The first step,
Modules. Modules Modules are the highest level program organization unit, usually correspond to source files and serve as libraries of tools. Each file.
Advanced Perl For Bioinformatics Part 1 2/23/06 1-4pm Module structure Module path Module export Object oriented programming Part 2 2/24/06 1-4pm Bioperl.
Programming in Perl references and objects Peter Verhás January 2002.
1 Using Perl Modules. 2 What are Perl modules?  Modules are collections of subroutines  Encapsulate code for a related set of processes  End in.pm.
Python: File Directories What is a directory? A hierarchical file system that contains folders and files. Directory (root folder) Sub-directory (folder.
Lecture 9: Basic concepts of Perl Modules. Functions (Subs) In perl functions take the following format: – sub subname – { my $var1 = $_[0]; statements.
Introduction to Bioinformatic Computation. Lecture
Python’s Modules Noah Black.
Module 1: Investigation 2 Repeating and Alternating Patterns
Modules and BioPerl.
Introduction to Bioinformatic Computation. Lecture
Fractals help.
Perl Modules.
Lesson 2. Control structures File IO - reading and writing Subroutines
References and Objects
Python Lesson’S 1 & 2 Mr. Kalmes.
Scripts In Matlab.
Review We've seen that a module is a file that can contain classes as well as its own variables. We've seen that you need to import it to access the code,
Presentation transcript:

How to write & use Perl Modules

What is a Module? A separate Namespace in a separate file with related functions/variables

What then is a Namespace? A namespace provides a certain context to functions/variables "my hammer", "Mary's lamb", "Gulliver's travels", "Dutch cheese","French bread", "your car"

What then is a Namespace? Suppose Jack and Harm both wrote a function to shuffle a sequence and you want to compare the two functions. If both called their function “shuffle”, how can you distinguish between them? -> Put each function in its own namespace

sub shuffle { #Harm’s implementation } sub shuffle { #Jack’s implementation } my $seq = "atgcatgata"; # This will not work!! print shuffle($seq);

# one solution... sub shuffleHarm { #Harm’s implementation } sub shuffleJack { #Jack’s implementation } my $seq = "atgcatgata"; print shuffleHarm($seq); print shuffleJack($seq);

#now using namespaces ('package') {#start of the ‘Harm’ block package Harm; sub shuffle { #Harm’s implementation } {#start of the ‘Jack’ block package Jack; sub shuffle { #Jack’s implementation }

my $seq = "atgcatgata"; print Harm::shuffle($seq); print Jack::shuffle($seq);

To turn this into modules, save Harm’s package in Harm.pm and Jack’s package in Jack.pm. Make sure the last line of each file is: 1; To use a package in your script, use the keyword “use” followed by the package name. The name of the module file usually is the name of the package, with the extension “.pm”.

# Harm.pm use strict; use warnings; package Harm; sub shuffle { #Harm’s implementation } 1;

Then the Perl script will be: use Harm; use Jack; my $seq = "atgcatgata"; print Harm::shuffle($seq); print Jack::shuffle($seq);

Import/Export Functions can also be exported by the module into the "main::" namespace use = = = qw(shuffl);

functions have to be explicitely imported: use Harm qw(&shuffle); use Jack; print shuffle($sequence); print Jack::shuffle($sequence);

location of the module file The locations where Perl looks for the module are listed in array, try: perl -V and look You can add to this path with the PERL5LIB environment variable, you can also specify an additional library path in the script: use lib '/path/to/lib';

Directory::module If you see a module reference like: Bio::Seq That means that the Seq module is in a directory called Bio: Bio/Seq.pm This can be used to group modules

Why use Modules? Organize the components of you program Separate large programs in functional blocks Code reuse A module can easily be included in a new script Sharing A module is a convenient way to publish or share your code with others. There are a lot of modules with a wide range of functions available for Perl. Check: