COMS 3101 Programming Languages: Perl. Lecture 6

Size: px
Start display at page:

Download "COMS 3101 Programming Languages: Perl. Lecture 6"

Transcription

1 COMS 3101 Programming Languages: Perl Lecture 6 Fall 2013 Instructor: Ilia Vovsha

2 Lecture Outline Concepts: Subroutine references Symbolic references Saving structures OOP (inheritance) More on modules: CPAN Prgamas: fields, base Module: Class::Struct Pod (plain old documentation) Common remarks 6.2

3 Concepts Subroutine references Copying referent Symbolic references Saving structures 6.3

4 Subroutine References Reference to a sub follows similar rules Can use backslash or anonymous sub max {. } # Anonymous $sub_ref = \&max; $sub_ref = sub {. }; # Calling subroutine &$sub_ref(); $sub_ref > (); $sub_ref > (1,4,6,8); # Call sub using string my %cmds = ( process => \&process_data, clear => \&clear_data, any => sub {.} ); $cmds{$str} > (); 6.4

5 Copy Referent To copy referent for another reference: $aref1 = [ 1,2,3 ]; $aref2 = [ 4,5,6 ]; $aref2 = $aref1 $aref2 = ]; $href2 = { %{$href1 } }; # Not a copy! Rather refers to the same location! # Create a new anonymous reference # Same approach for hashes 6.5

6 Symbolic References Refers to the name of a variable If we try to dereference, we get access to variable! Can be dangerous! (use strict refs to prohibit) $N = V ; $$N = 5; # Set scalar $V = 5 $N > [0] = 6; # Set element 0 of array V to 6 $N > {key} = 7; # Set key of hash V to 7 &$N; # Call sub V 6.6

7 Saving Data Structures Save any DS to use later: Data::Dumper module Turn DS into a string, save externally to a file, read in the file and recover DS with eval / do CPAN module Storable: more efficient, but cannot be shared across different architectures use Data::Dumper; open (OUTFILE, > filename ); print OUTFILE Data::Dumper >Dump([\%hash], [ *hash ]); open (INFILE, < filename ); undef $/; # undef record separator, read entire file eval <INFILE>; # recreate %hash use Storable; store(\%hash, filename ); $href = retrieve( filename ); %hash = % { retrieve( filename ) } ; 6.7

8 OOP (inheritance) We can define a hierarchy of classes to share methods between them Derived d/ sub class inherits i methods from base / parent / super class The super classes are specified in array (declared with our) of the derived class. Each element of the array is a package (class) name Single Inheritance: one parent class (search parent for methods) Multiple Inheritance: multiple parent classes (search left to right array, depth first order) Once method is found, store in cache for efficiency is changed, the cache is invalidated (avoid it if you can!) Constructor Inheritance: no automatic call to base class constructor 6.8

9 OOP (method search) If method not defined in class: at runtime when a call is made Search order given multiple l parent classes: lftt left to right ihtthrough array, depth first # Nissan.pm package Nissan; = (Car, Truck); # Call: Nissan >new() >build( sedan ); # Search order: 1. Check if method (build) is defined in class (Nissan) 2. Check if method is defined in $Nissan::ISA[0] (Car class) 3. Check if method is defined (Car array) 4. When done with ISA[0], repeat steps 2,3, for ISA[1] (Truck class) 6.9

10 Scoped Variables my creates private variable visible only within block hidden from outside of enclosing scope, and hides previously declared variables with identical name confines name & value to scope suitable for scalar/array/hash variables our confines name only to scope (no effect on visibility) suitable for scalar/array/hash variables used to access global variables, their initial value inside block unchanged effects or assignmentpersist after the scope of declaration (block) local confines value only to scope suitable for scalar/array/hash + more variables initial value for variable is () or undef value of variable is restored no matter how you exit the block (changes thrown away) dynamic scope: value of variable depends on scope & changes during run time my is preferable over local APP

11 Scoped Variables (example) $office = "global"; &say(); &barney(); &fred(); &say(); sub say { print "$office\n"; } # Global $office # prints "global" # prints "barney global", lexical scope; # prints "fred fred", dynamic scope, # prints "global", restored after &fred() # print the $office sub barney { my $office = "barney"; print "$office "; &say(); } sub fred { local $office = "fred"; print "$office "; &say(); } APP

12 CPAN Comprehensive Perl Archive Network: repository for modules Installing a module: # Download the.gz file from CPAN, unzip and go to proper directory # Build: perl MakeFile.pl make make test # Install: make install Alternative: install cpanm module cpan App::cpanminus # Install cpanm cpanm Module::Name # get, unpack, build, and install modules 6.12

13 Method invocation (indirect) Direct approach: arrow operator INVOCANT >METHOD() Indirect approach: can be ambiguous METHOD INVOCANT ARGS $mazda = Car > new(); $mazda > drive( slow ); $mazda = new Car; drive $mazda slow ; # Class: Car, Method: new, Object: $mazda # Instance: $mazda, Method: drive # Same as above 6.13

14 Pseudohashes (deprecated!) Pseudohash: reference to array whose 1 st element is reference to hash Purpose: can be treated t as array ref or hash href Deprecated: slower, muddling, problems with multiple inheritance Alternatives: restricted hashes (Hash::Util) $ph_ref = [ {maker => 1, color => 2}, mazda, red ]; # Definition $ph_ref >{color}; # Access element (href) $ph_ref ref >[2]; # Access element (aref) $ph_ref >[0]{cost} = 3; $ph_ref >[3] = cheap ; # Add element 6.14

15 fields pragma Experimental feature, enables compile time type verified class fields Note: pseudohashes h removed from perl The related base pragma provides for field inheritance from parent class fields::new() creates and blesses a pseudohash comprised of the fields declared using the fields pragma into the specified class. package Car; package Car; use fields qw(maker color cost); sub new { my $class = shift; sub new { my $self = { my $class = shift; maker => mazda, my $self = fields::new($class); color => red, cost => $self >{maker} = mazda ; }; $self >{color} = red ; bless ($self, $class); return $self; return $self; } } 6.15

16 fields pragma (example) Prevents typos in field names (otherwise accepted): package Car; use fields qw(maker color cost); sub new { my $class = shift; my $self = fields::new($class); $self >{maker} = mazda ; $self >{color} = red ; return $self; } sub some_fun { my $self = shift; $self >{colour} = blue ; } # Compiler throws error! 6.16

17 base pragma Simplifies inheritance in two ways: Assigns without having to declare Inherits fields of parent class if fields pragma is used Problem: multiple inheritance is not supported! (raises exception if more than one base class uses fields ) package Mazda; use base qw(car); use fields qw(vehicle mpg); sub new { my $class = shift; my $self = fields::new($class); l $self >{maker} = mazda ; $self >{mpg} = 25; return $self; } # Mazda is subclass of Car # Inherits fields from Car class, adds two new fields # inherited # own attribute 6.17

18 Class::Struct module Standard module to declare a record like class struct t function provides for constructor t and accessor methods on the fly Constructor named new Accessor method for each member specified by the hash reference package Car; use Class::Struct; struct Car => { name => $, # Scalar variable ibl size # array variable specs => %, # hash variable } 1; type => Truck, # Truck object use Car; $kia = Car > new(); $kia > name( CX5 ); $aref = $kia >size; $kia > size(0,100); $href = $kia >specs; $kia > specs( color, white ); 6.18

19 Pod Plain Old Documentation: simple text markup format Simple to use, not too expressive Embed documentation in Perl modules and scripts Translators: convert Pod to various formats pod2text, pod2html, pod2latex Content tdivided id d into paragraphs by empty lines: verbatim: begins with tabs/spaces (left unformatted) command: begins with equal sign (format according to directive) ordinary: begins with something else (minimal formatting) Perl engine throws out all Pod markup 6.19

20 Pod (example) =head1 Boring Module Synopsis Some I<boring> text about the module followed by even more B<boring> code =cut use Boring ; my $object = Boring >new(); sub some_fun { print Documentation ; print is for old people!\n ; } =pod 6.20

21 Pod (example ctd) =head2 List of methods =over 4 =item 1. First method enforces mild boredom =item 2. Second method puts you to sleep =back 6.21

22 Exercise (In Class) Remove specific field from a list Suppose you have a row of data stored in a string. The fields of your row may be separated with any delimiter(s). For example: Name Height Weight 2. Write a subroutine that deletes the Nth field (N is an argument), and returns the shortened string. 6.22

23 Common Remarks Filehandles: open($fh, >filename ); print $fh ABC, \t, DEF ; # works fine print $fh, ABC, \t, DEF ; # WRONG: prints to STDOUT Context: ($x) = (aa,bb,cc); # $x gets value aa $x = (aa,bb,cc); # $x gets value = (aa,bb,cc); $x # $x =

24 Common Remarks Efficiency: hashes instead of linear searches # Search $word # Method 1: foreach (@keywords) { print yes if ($word eq $) $_); } # Method 2 (potentially more efficient): %h; for (@keywords) { $h{$_}++; } print yes if ($h{$word} > 0); 6.24

25 Common Remarks Efficiency: print with comma not. print Mr., $name, is next ; print Mr.. $name. is next ; # faster Db Debugging is problematic: use warnings Planning to share code: use strict 6.25

26 Error Handling Relevant functions: Build in: warn, die Carp module: carp, cluck, croak, confess Choosing the proper function: Raise a warning and then continue or terminate execution? What should the error message report? filename & line number / caller s info open($fh, fname ) or warn Warning Message ; open($fh, fname ) or die Warning Message ; # warn: just a warning, message printed to STDERR # die: similar to warn, but also calls exit (terminates execution) 6.26

27 Error Handling (in modules) Carp module: use Carp Debugging a module: report module s name & line number (warn, die) Debugging the script: report caller s info (carp / cluck, croak / confess) package Job; use Carp; sub some_fun { warn Error ; # carp Error ; # croak Error ; # cluck Error ; } 1; # confess Error ; use Job; Job::some_fun(); # Prints the following: # warn: Error at Job.pm line 5. # warn: Error at test.pl line 3. # die: Error at test.pl line 3. # warn: Error at Job.pm line 5. # Job::some_fun() called at test.pl line 3. # die: Error at Job.pm line 5. # Job::some_fun() called at test.pl line

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

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

CP150 - Advanced Perl Programming

CP150 - Advanced Perl Programming Corder Enterprises International Building World Class MIS Teams, for you! CP150 - Advanced Perl Programming Course Description: Perl has evolved from its beginnings as an eclectic scripting tool for UNIX

More information

COMS 3101 Programming Languages: Perl. Lecture 1

COMS 3101 Programming Languages: Perl. Lecture 1 COMS 3101 Programming Languages: Perl Lecture 1 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl What is Perl? Perl is a high level language initially developed as a scripting

More information

Learning Perl Objects, References, and Modules

Learning Perl Objects, References, and Modules Learning Perl Objects, References, and Modules Randal L. Schwartz with Tom Phoenix HLuHB Darmstadt Illlllllllllllllllllllll 15760214 O'REILLY* Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

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

COMS 3101 Programming Languages: Perl. Lecture 3

COMS 3101 Programming Languages: Perl. Lecture 3 COMS 3101 Programming Languages: Perl Lecture 3 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Array / Hash manipulation (continued) Pattern Matching

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

Object Oriented Programming with Perl

Object Oriented Programming with Perl Object Oriented Programming with Perl Yet Another Perl Conference Amsterdam, August 2 4, 2001 2001 Squirrel Consultancy. All rights reserved. Object Oriented Programming with Perl Preface 2001 Squirrel

More information

NAME SYNOPSIS. Perl version documentation - Pod::Parser. Pod::Parser - base class for creating POD filters and translators.

NAME SYNOPSIS. Perl version documentation - Pod::Parser. Pod::Parser - base class for creating POD filters and translators. NAME SYNOPSIS Pod::Parser - base class for creating POD filters and translators use Pod::Parser; package MyParser; @ISA = qw(pod::parser); sub command { my ($parser, $command, $paragraph, $line_num) =

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

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

Intermediate Perl Table of Contents Intermediate Perl Foreword Preface Structure of This Book Conventions Used in This Book Using Code Examples

Intermediate Perl Table of Contents Intermediate Perl Foreword Preface Structure of This Book Conventions Used in This Book Using Code Examples Intermediate Perl Table of Contents Intermediate Perl Foreword Preface Structure of This Book Conventions Used in This Book Using Code Examples Comments and Questions Safari Enabled Acknowledgments Chapter

More information

NAME SYNOPSIS. Perl version documentation - Pod::Parser. Pod::Parser - base class for creating POD filters and translators.

NAME SYNOPSIS. Perl version documentation - Pod::Parser. Pod::Parser - base class for creating POD filters and translators. NAME SYNOPSIS Pod::Parser - base class for creating POD filters and translators use Pod::Parser; package MyParser; @ISA = qw(pod::parser); sub command { my ($parser, $command, $paragraph, $line_num) =

More information

G52CPP C++ Programming Lecture 7. Dr Jason Atkin

G52CPP C++ Programming Lecture 7. Dr Jason Atkin G52CPP C++ Programming Lecture 7 Dr Jason Atkin 1 This lecture classes (and C++ structs) Member functions inline functions 2 Last lecture: predict the sizes 3 #pragma pack(1) #include struct A

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

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

Hash::Util::FieldHash offers a number of functions in support of The Inside-out Technique of class construction.

Hash::Util::FieldHash offers a number of functions in support of The Inside-out Technique of class construction. NAME SYNOPSIS Hash::Util::FieldHash - Support for Inside-Out Classes ### Create fieldhashes use Hash::Util qw(fieldhash fieldhashes); # Create a single field hash fieldhash my %foo; # Create three at once...

More information

CS 105 Perl: Modules and Objects

CS 105 Perl: Modules and Objects CS 105 Perl: Modules and Objects February 20, 2013 Agenda Today s lecture is an introduction to Perl modules and objects, but first we will cover a handy feature Perl has for making data structures. Where

More information

use attributes (); # optional, to get subroutine declarations = attributes::get(\&foo);

use attributes (); # optional, to get subroutine declarations = attributes::get(\&foo); NAME SYNOPSIS attributes - get/set subroutine or variable attributes sub foo : method ; my ($x,@y,%z) : Bent = 1; my $s = sub : method {... ; use attributes (); # optional, to get subroutine declarations

More information

@EXPORT_OK = qw(munge frobnicate); # symbols to export on request

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

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 9/20/2013 Context and Modules (Perl) Scripting as Glue 1 Outline Programming in the large Scripting as glue 2 Modules Module = file p/q.pm that starts with declaration

More information

Be sure to read ENCODING if your Pod contains non-ascii characters.

Be sure to read ENCODING if your Pod contains non-ascii characters. NAME Pod::Simple - framework for parsing Pod SYNOPSIS TODO DESCRIPTION Pod::Simple is a Perl library for parsing text in the Pod ("plain old documentation") markup language that is typically used for writing

More information

G52CPP C++ Programming Lecture 9

G52CPP C++ Programming Lecture 9 G52CPP C++ Programming Lecture 9 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture const Constants, including pointers The C pre-processor And macros Compiling and linking And

More information

Perl (5 Days Content)

Perl (5 Days Content) Perl (5 Days Content) Pre-requisites: Knowledge of any programming language ( C / C++ / Shell Scripting) Objective of the Course: The participants should be in a position to understand Perl Scripts written

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

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

1. Introduction. 2. Scalar Data

1. Introduction. 2. Scalar Data 1. Introduction What Does Perl Stand For? Why Did Larry Create Perl? Why Didn t Larry Just Use Some Other Language? Is Perl Easy or Hard? How Did Perl Get to Be So Popular? What s Happening with Perl Now?

More information

use Log::Message private => 0, config => '/our/cf_file'; my $log = Log::Message->new( private => 1, level => 'log', config => '/my/cf_file', );

use Log::Message private => 0, config => '/our/cf_file'; my $log = Log::Message->new( private => 1, level => 'log', config => '/my/cf_file', ); NAME Log::Message - A generic message storing mechanism; SYNOPSIS use Log::Message private => 0, config => '/our/cf_file'; my $log = Log::Message->new( private => 1, => 'log', config => '/my/cf_file',

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

package CLASS_NAME; use Class::Struct; # declare struct, based on array, implicit class name: struct( ELEMENT_NAME => ELEMENT_TYPE,...

package CLASS_NAME; use Class::Struct; # declare struct, based on array, implicit class name: struct( ELEMENT_NAME => ELEMENT_TYPE,... NAME SYNOPSIS Class::Struct - declare struct-like datatypes as Perl classes # declare struct, based on array: struct( CLASS_NAME => [ ELEMENT_NAME => ELEMENT_TYPE,... ]); # declare struct, based on hash:

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

By default, optional warnings are disabled, so any legacy code that doesn't attempt to control the warnings will work unchanged.

By default, optional warnings are disabled, so any legacy code that doesn't attempt to control the warnings will work unchanged. SYNOPSIS use warnings; no warnings; use warnings "all"; no warnings "all"; use warnings::register; if (warnings::enabled()) warnings::warn("some warning"); if (warnings::enabled("void")) warnings::warn("void",

More information

autodie - Replace functions with ones that succeed or die with lexical scope # Recommended: implies 'use autodie qw(:default)'

autodie - Replace functions with ones that succeed or die with lexical scope # Recommended: implies 'use autodie qw(:default)' NAME autodie - Replace functions with ones that succeed or die with lexical scope SYNOPSIS # Recommended: implies 'use autodie qw(:default)' use autodie qw(:all); # Recommended more: defaults and system/exec.

More information

Table of Contents Preface Bare Necessities... 17

Table of Contents Preface Bare Necessities... 17 Table of Contents Preface... 13 What this book is about?... 13 Who is this book for?... 14 What to read next?... 14 Personages... 14 Style conventions... 15 More information... 15 Bare Necessities... 17

More information

$syntax_okay = podchecker($filepath, $outputpath, %options);

$syntax_okay = podchecker($filepath, $outputpath, %options); NAME Pod::Checker, podchecker() - check pod documents for syntax errors SYNOPSIS use Pod::Checker; $syntax_okay = podchecker($filepath, $outputpath, %options); OPTIONS/ARGUMENTS podchecker() DESCRIPTION

More information

Beginning Perl. Third Edition. Apress. JAMES LEE with SIMON COZENS

Beginning Perl. Third Edition. Apress. JAMES LEE with SIMON COZENS Beginning Perl Third Edition JAMES LEE with SIMON COZENS Apress About the Author... About the Technical Reviewers Acknowledgements Suitrod yetion «. xvi xvii xviii «xix. Chapter 1: First Steps in Perl..

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

Fortunately, the layout is much more legible, more like BASIC's PRINT USING statement. Think of it as a poor man's nroff(1). nroff

Fortunately, the layout is much more legible, more like BASIC's PRINT USING statement. Think of it as a poor man's nroff(1). nroff NAME DESCRIPTION perlform - Perl formats Perl has a mechanism to help you generate simple reports and charts To facilitate this, Perl helps you code up your output page close to how it will look when it's

More information

Defining Classes and Methods

Defining Classes and Methods Defining Classes and Methods Chapter 5 Modified by James O Reilly Class and Method Definitions OOP- Object Oriented Programming Big Ideas: Group data and related functions (methods) into Objects (Encapsulation)

More information

PS1-MOPS SOURCE CODE DOCUMENTATION

PS1-MOPS SOURCE CODE DOCUMENTATION PS1-MOPS SOURCE CODE DOCUMENTATION DRAFT D. Chang Institute for Astronomy University of Hawaii at Manoa An overview of using Doxygen to processed embedded documentation in PS1-MOPS Perl source code is

More information

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

Subroutines in Perl. Jon-Michael Deldin. Dept. of Computer Science University of Montana September 12, 2011 Subroutines in Perl Jon-Michael Deldin Dept. of Computer Science University of Montana jon-michael.deldin@mso.umt.edu September 12, 2011 Jon-Michael Deldin (UM) Subroutines in Perl September 12, 2011 1

More information

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

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

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access. ENCAPSULATION private, public, scope and visibility rules. packages and package level access. Q. Explain the term Encapsulation with an example? Ans: The wrapping up to data and methods into a single units

More information

use CGI::Carp qw(fatalstobrowser); die "Fatal error messages are now sent to browser";

use CGI::Carp qw(fatalstobrowser); die Fatal error messages are now sent to browser; NAME SYNOPSIS CGI::Carp - CGI routines for writing to the HTTPD (or other) error log use CGI::Carp; croak "We're outta here!"; confess "It was my fault: $!"; carp "It was your fault!"; warn "I'm confused";

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

Lecture 18 CSE11 Fall 2013 Inheritance

Lecture 18 CSE11 Fall 2013 Inheritance Lecture 18 CSE11 Fall 2013 Inheritance What is Inheritance? Inheritance allows a software developer to derive a new class from an existing one write code once, use many times (code reuse) Specialization

More information

use Params::Check qw[check allow last_error];

use Params::Check qw[check allow last_error]; NAME SYNOPSIS Params::Check - A generic input parsing/checking mechanism. use Params::Check qw[check allow last_error]; sub fill_personal_info { my %hash = @_; my $x; my $tmpl = { firstname => { required

More information

Shells and Shell Programming

Shells and Shell Programming Shells and Shell Programming 1 Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed

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

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 6/7/2012 Textual data processing (Perl) CS 5142 Cornell University 9/7/13 1 Administrative Announcements Homework 2 due Friday at 6pm. First prelim 9/27, Review on

More information

Pathologically Eclectic Rubbish Lister

Pathologically Eclectic Rubbish Lister Pathologically Eclectic Rubbish Lister 1 Perl Design Philosophy Author: Reuben Francis Cornel perl is an acronym for Practical Extraction and Report Language. But I guess the title is a rough translation

More information

C++ Inheritance and Encapsulation

C++ Inheritance and Encapsulation C++ Inheritance and Encapsulation Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance Private vs. Protected Private: private members

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

# start with SSL, e.g. nntps $nntp = Net::NNTP->new("some.host.name", SSL => 1);

# start with SSL, e.g. nntps $nntp = Net::NNTP->new(some.host.name, SSL => 1); NAME Net::NNTP - NNTP Client class SYNOPSIS use Net::NNTP; $nntp = Net::NNTP->new("some.host.name"); $nntp->quit; # start with SSL, e.g. nntps $nntp = Net::NNTP->new("some.host.name", SSL => 1); DESCRIPTION

More information

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.) INTRODUCTION TO.NET Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.) CLR Architecture and Services The.Net Intermediate Language (IL) Just- In-

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 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

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017 Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable

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

The Eobj Perl environment

The Eobj Perl environment The Eobj Perl environment Eli Billauer elib@flextronics.co.il http://search.cpan.org/author/billauer/ The Eobj Perl environment p.1 Lecture overview Introduction: Me, Eobj and OO programming Eobj classes

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

Exception Handling. Chapter 9

Exception Handling. Chapter 9 Exception Handling Chapter 9 Objectives Describe the notion of exception handling React correctly when certain exceptions occur Use Java's exception-handling facilities effectively in classes and programs

More information

$syntax_okay = podchecker($filepath, $outputpath, %options);

$syntax_okay = podchecker($filepath, $outputpath, %options); NAME Pod::Checker - check pod documents for syntax errors SYNOPSIS use Pod::Checker; $syntax_okay = podchecker($filepath, $outputpath, %options); my $checker = Pod::Checker->new(%options); $checker->parse_from_file($filepath,

More information

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Indian Institute of Technology Kharagpur PERL Part II Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Kharagpur, INDIA Lecture 22: PERL Part II On completion, the student will be able

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

Clarifying Roles. Jonathan Worthington German Perl Workshop 2007

Clarifying Roles. Jonathan Worthington German Perl Workshop 2007 Clarifying Roles Jonathan Worthington German Perl Workshop 2007 The Perl 6 Object Model The Perl 6 object model attempts to improve on the Perl 5 one Nicer, more declarative syntax One way to do things,

More information

Scripting Languages Perl Basics. Course: Hebrew University

Scripting Languages Perl Basics. Course: Hebrew University Scripting Languages Perl Basics Course: 67557 Hebrew University אליוט יפה Jaffe Lecturer: Elliot FMTEYEWTK Far More Than Everything You've Ever Wanted to Know Perl Pathologically Eclectic Rubbish Lister

More information

What is Inheritance?

What is Inheritance? Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting

More information

COMP284 Scripting Languages Lecture 6: Perl (Part 5) Handouts

COMP284 Scripting Languages Lecture 6: Perl (Part 5) Handouts COMP284 Scripting Languages Lecture 6: Perl (Part 5) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

use File::Find; find({ wanted => \&process, follow => 1 }, '.');

use File::Find; find({ wanted => \&process, follow => 1 }, '.'); NAME SYNOPSIS File::Find - Traverse a directory tree. find(\&wanted, @directories_to_search); sub wanted {... } finddepth(\&wanted, @directories_to_search); sub wanted {... } DESCRIPTION find({ wanted

More information

Perl. Perl. Perl. Which Perl

Perl. Perl. Perl. Which Perl Perl Perl Perl = Practical Extraction and Report Language Developed by Larry Wall (late 80 s) as a replacement for awk. Has grown to become a replacement for awk, sed, grep, other filters, shell scripts,

More information

Shells and Shell Programming

Shells and Shell Programming Shells and Shell Programming Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed

More information

print STDERR "This is a debugging message.\n";

print STDERR This is a debugging message.\n; NAME DESCRIPTION perlopentut - simple recipes for opening files and pipes in Perl Whenever you do I/O on a file in Perl, you do so through what in Perl is called a filehandle. A filehandle is an internal

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 4 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA

More information

$pat = '(?{ $foo = 1 })'; use re 'eval'; /foo${pat}bar/; # won't fail (when not under -T # switch)

$pat = '(?{ $foo = 1 })'; use re 'eval'; /foo${pat}bar/; # won't fail (when not under -T # switch) NAME SYNOPSIS re - Perl pragma to alter regular expression behaviour use re 'taint'; ($x) = ($^X =~ /^(.*)$/s); # $x is tainted here $pat = '(?{ $foo = 1 })'; use re 'eval'; /foo${pat}bar/; # won't fail

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

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 7

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 7 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 7 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Essential

More information

Defensive Programming

Defensive Programming Defensive Programming Software Engineering CITS1220 Based on the Java1200 Lecture notes by Gordon Royle Lecture Outline Why program defensively? Encapsulation Access Restrictions Documentation Unchecked

More information

PROGRAMMING LANGUAGE 2

PROGRAMMING LANGUAGE 2 31/10/2013 Ebtsam Abd elhakam 1 PROGRAMMING LANGUAGE 2 Java lecture (7) Inheritance 31/10/2013 Ebtsam Abd elhakam 2 Inheritance Inheritance is one of the cornerstones of object-oriented programming. It

More information

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell. Command Interpreters A command interpreter is a program that executes other programs. Aim: allow users to execute the commands provided on a computer system. Command interpreters come in two flavours:

More information

Creating Dynamic Websites with CGI and Mason - Day Two. Jon Warbrick University of Cambridge Computing Service

Creating Dynamic Websites with CGI and Mason - Day Two. Jon Warbrick University of Cambridge Computing Service Creating Dynamic Websites with CGI and Mason - Day Two Jon Warbrick University of Cambridge Computing Service Introducing Mason What's wrong with CGI? Mixing code and HTML is a bad idea Repeated re-execution

More information

Perl Distilled. Introduction. References. December 2010 Martin Jones. Copyright 2010 Ignition Training LLC, Some Rights Reserved

Perl Distilled. Introduction. References. December 2010 Martin Jones. Copyright 2010 Ignition Training LLC, Some Rights Reserved Introduction Perl Distilled December 2010 Martin Jones Using a programming language requires a programmer to possess a model of how that language works. Knowing the model does not preclude working to the

More information

In spite of its name, h2xs may also be used to create a skeleton pure Perl module. See the -X option.

In spite of its name, h2xs may also be used to create a skeleton pure Perl module. See the -X option. NAME h2xs - convert.h C header files to Perl extensions SYNOPSIS h2xs [OPTIONS...] [headerfile... [extra_libraries]] DESCRIPTION OPTIONS h2xs -h -? --help h2xs builds a Perl extension from C header files.

More information

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

IST311. Advanced Issues in OOP: Inheritance and Polymorphism IST311 Advanced Issues in OOP: Inheritance and Polymorphism IST311/602 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition

More information

NAME DESCRIPTION. Declarations. Perl version documentation - perlsyn. perlsyn - Perl syntax

NAME DESCRIPTION. Declarations. Perl version documentation - perlsyn. perlsyn - Perl syntax NAME DESCRIPTION Declarations perlsyn - Perl syntax A Perl program consists of a sequence of declarations and statements which run from the top to the bottom. Loops, subroutines and other control structures

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

CS 105 Perl: Completing the Toolbox

CS 105 Perl: Completing the Toolbox CS 105 Perl: Completing the Toolbox March 4, 2013 Agenda autodie with open Inspecting scalars perl -c Unary coercion Topicalization ~~ Unique list idiom Schwartzian Transform Using // for defaults and

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

Assertions, pre/postconditions

Assertions, pre/postconditions Programming as a contract Assertions, pre/postconditions Assertions: Section 4.2 in Savitch (p. 239) Specifying what each method does q Specify it in a comment before method's header Precondition q What

More information

DOT NET Syllabus (6 Months)

DOT NET Syllabus (6 Months) DOT NET Syllabus (6 Months) THE COMMON LANGUAGE RUNTIME (C.L.R.) CLR Architecture and Services The.Net Intermediate Language (IL) Just- In- Time Compilation and CLS Disassembling.Net Application to IL

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

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

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

Module 10 Inheritance, Virtual Functions, and Polymorphism

Module 10 Inheritance, Virtual Functions, and Polymorphism Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:

More information

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led CENTER OF KNOWLEDGE, PATH TO SUCCESS Website: PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO 2010 Course: 10550A; Duration: 5 Days; Instructor-led WHAT YOU WILL LEARN This course teaches you

More information