Chapter 11 the Perl Scripting Language Dr

Total Page:16

File Type:pdf, Size:1020Kb

Chapter 11 the Perl Scripting Language Dr Chapter 11 The Perl Scripting Language Dr. Marjan Trutschl [email protected] Louisiana State University, Shreveport, LA 71115 Chapter 11 The Perl Scripting Language ¤ Intro to Perl ¤ Working with Files ¤ Help ¤ Sort ¤ Terminology ¤ Subroutines ¤ Running a Perl Program ¤ Regular Expressions ¤ Syntax ¤ CPAN Modules ¤ Variables ¤ Examples ¤ Control Structures Intro to Perl ¤ The Perl motto is "There's more than one way to do it." Divining how many more is left as an exercise to the reader. ¤ Originally created by Larry Wall as a tool to process reports Yep. This guy. at NASA, AKA the Practical Extraction and Report Language ¤ Perl is easy, flexible and processes text information quickly ¤ Since most graphics are text at some level, Perl has been adapted to CGI pretty widely ¤ It’s also great at RegExp and works very well with Linux by allowing embedded bash in a Perl script or Perl in a bash script Help ¤ Help ¤ There are numerous resources for Perl, so please don’t stop with just the text ¤ Try reading the documentation…it’s actually very well written and provides sound advice ¤ Also, if you’re in a hurry, try this tutorial: ¤ http://www.perl.com/pub/2008/04/23/a-beginners- introduction-to-perl-510.html Perl is already installed on the Sun servers or any OSX system, but some Linux distributions (like raspbian) don’t ship with it. Simply install it with ‘apt-get’ or your favorite package manager. Help ¤ Documentation ¤ Because Perl’s restrictions can be turned off, it’s easy to use it for simple tasks with sloppy code ¤ Turn on ‘strict’ and ‘warnings’ to tighten up your code ¤ Perl supports object oriented code, though there is no special syntax for it, feel free to write good code ¤ Constructors can be created using the ‘bless’ function ¤ Use the ‘perldoc’ utility to document Larry is very religious, and has a good sense of humor about it. Terminology ¤ Terminology ¤ Module: Similar to an API, it’s a piece of code containing several functions that work together ¤ Distribution: A set of modules that perform a task ¤ Package: The Perl term for a namespace, it defines a variable in relation to a distribution or module to prevent collisions ¤ Block: Statements within curly braces that defines a scope ¤ Package variable: A variable with a scope limited to the current package ¤ Lexical variables: Locally defined variables by the ‘my’ keyword, since the ‘local’ keyword was already taken Terminology ¤ Terminology (cont) ¤ List: A set of comma separated values in parentheses ¤ Array: An ordered list of scalar variables, indexed by number ¤ Hash: Unordered collection of scalar values indexed by their associated string key ¤ Scalar: A value, in the form of a number, string or reference ¤ Compound Statement: A collection of statements, within one or more blocks Running a Perl Program ¤ Running Perl ¤ Perl can be run from the command line or a script ¤ Use a ‘.pl’ file extension when writing scripts and a shebang using the ‘which’ utility ¤ Terminate lines in a script with a semicolon ¤ Just like bash, use ‘chmod’ to give execute permission to the script and run it with ‘./’ from within the same directory The ‘use strict’ and ‘use warnings’ enforce better coding practices, but are optional Syntax ¤ Perl Syntax ¤ Perl’s syntax is similar to C, which is similar to bash ¤ Quotation Mark: These act like bash, where double quotes allow expansion of variables and single quotes do not. ¤ Statement: Each statement is terminated by a semicolon, unless it’s the final statement in a block ¤ Slash: The lead guitarist for Guns and Roses, or a delimiter for Regular Expressions ¤ Backslash: Escape character ¤ Hashmark: #comments #sorrynotsorry Variables ¤ Three Types of Variables ¤ $scalar: Scalar variables contain a single value ¤ @array: Arrays contain multiple values, indexed by number and starting at 0 ¤ %hash: Hashes contain references to data, or an associative array ¤ Syntax ¤ Variable names are case sensitive and can include letters, digits and the underscore ¤ Package Qualifiers are designated by ‘::’ or a single quote Variables ¤ Usage of Variables ¤ If a lexical (local) variable has the same name as a package variable, Perl uses the lexical variable within the block ¤ Use ‘my’ to keep all variables local, particularly in larger software packages, to prevent confusion ¤ Use ‘our’ to use a package variable of the same name ¤ Variables do not need to be declared before usage, which can lead to bugs ¤ Turn on ‘use strict’ to prevent this to prevent typos from turning into bugs ¤ Turn on ‘use warnings’ to get a notification that a variable is used without initialization Variables ¤ Scalar Variables ¤ Scalar, or singular, variables are prefixed by ‘$’ and hold a single value ¤ Using ‘my’ will identify them as Lexical (or local) variables ¤ Scalars and RegExp ¤ When Perl finds a RegExp match, then it will store it in a variable $1 through $9 ¤ Since these are lexical variables and easily clobbered, keep them from disappearing outside of the block by assigning them to another variable Variables ¤ Array Variables ¤ Arrays used zero based indexing, so they start at 0 ¤ There is no set limit to the size of an array, but it will return ‘undef’ when an array index is accessed out of bounds ¤ Double quote strings in arrays ¤ There are many different ways to deal with arrays, but a lot fewer when ‘strict’ is enabled ¤ Access sequential array items using an array slice ¤ ‘..’ Prints continuous entries, while ‘,’ prints specific entries ¤ Use double quotes to print spaces between entries Variables ¤ Array Sample ¤ Here are some simple array samples to try out for practice Why would you ever need an array that’s not a linked list? Perl dispenses with the unnecessary. Variables ¤ Hash Variables ¤ A hash, unlike an array, is unordered and values are accessed by a string value called a key ¤ Hashing will speed up finding data in large data sets, and Perl runs like many others at O(1) with a worst case O(n) ¤ This makes the normal use case to use a hash to link to a scalar value, improving the search performance Hashes in Perl are a little different. Since they only map to one value (which can be an array), they are ideally suited as dictionaries. Once the search key is placed in a hash table, the search is basically free. The value in the dictionary can easily be stored in a format for an address book or other kind of table Control Structures ¤ Perl Control Structures ¤ Perl operates like most other C based languages with some minor differences ¤ if/unless: Simplifies some nested if/else statements when a nullifier is required ¤ foreach: There is an alternative ‘for’ syntax that might look familiar, but they are synonymous ¤ last and next: Like skips or jumps, ‘next’ will return directly to the conditional while ‘last’ exits from the loop ¤ while and until: These are identical, except that ‘while’ continues to loop when the conditional evaluates to false and ‘until’ continues until it evaluates to true Working with Files ¤ File Handles ¤ Refers to a file or process that is open for reading or writing ¤ Similar to bash, Perl opens handles for input, output and error ¤ STDIN, STDOUT and STDERR ¤ Other handles must be manually opened ¤ This sounds hard, but really, they’re not very heavy ¤ Give the file handle any name you like ¤ Once opened, simply write to it using the ‘print’ function ¤ Or assign the handle to STDOUT so all output defaults to it ¤ “Magic” file handles are set through command line arguments Working with Files ¤ File Handles ¤ A brief note about file handles: The convention is to use all caps when writing ‘bareword’ file handles, because they are global variables. Because of this, they can cause collisions and can be more easily used by hackers. Since they are input directly, they also don’t give the program a chance to filter the input through string validation. Get into the habit of using three argument opens. Many reasonable people disagree on this topic, but the safest route is three argument file handles by reference. ¤ Optionally, this is also where you would specify character encoding, as part of the second argument Working with Files Working with Files ¤ Further Notes ¤ ‘chomp’ and ‘chop’ remove extra newlines and spaces, respectively ¤ ‘$!’ holds the last system error, if you’d like to print a full error message with some verbosity ¤ ‘$ARGV’ holds the argument from the command line, useful if your program reads in a filename Sort ¤ Sort ¤ The Perl ‘sort’ is a little more refined than bash ¤ It sorts numerically or alphabetically, based on ‘locale’ setting ¤ ‘reverse’ doesn’t sort, it simply swaps array values This sort might not work as expected. It sorts based on character sequence in the ASCII table. There are several ways to deal with this. Sort ¤ Sort ¤ If you’d like to sort numbers as integers, you’ll need to get it to compare things differently This sort works as expected with integers, but uses a couple of odd things. The ‘<=>’ “spaceship operator” The ‘$a’ and ‘$b’ variables should is a three way comparison only be used for sorting (although operator, which returns 1, 0 or -1. they work outside of it) because So you quickly get less than, they are specialized to the task. greater than and equal to results Don’t lexicalize them with ‘my’. from one comparison Subroutines ¤ Locality and Subroutines ¤ In Perl, all variables default to package level ¤ Local variables are declared with the ‘my’ keyword and package variables are declared with ‘our’ ¤ When creating subroutines, sometimes we want variables to be accessible outside of their block, so package is good ¤ The @_ array variable is local to the subroutine, but aliases the values in the calling argument, allowing it to pass parameters ¤ So you can pass in as many parameters as you’d like.
Recommended publications
  • Chapter 5 Names, Bindings, and Scopes
    Chapter 5 Names, Bindings, and Scopes 5.1 Introduction 198 5.2 Names 199 5.3 Variables 200 5.4 The Concept of Binding 203 5.5 Scope 211 5.6 Scope and Lifetime 222 5.7 Referencing Environments 223 5.8 Named Constants 224 Summary • Review Questions • Problem Set • Programming Exercises 227 CMPS401 Class Notes (Chap05) Page 1 / 20 Dr. Kuo-pao Yang Chapter 5 Names, Bindings, and Scopes 5.1 Introduction 198 Imperative languages are abstractions of von Neumann architecture – Memory: stores both instructions and data – Processor: provides operations for modifying the contents of memory Variables are characterized by a collection of properties or attributes – The most important of which is type, a fundamental concept in programming languages – To design a type, must consider scope, lifetime, type checking, initialization, and type compatibility 5.2 Names 199 5.2.1 Design issues The following are the primary design issues for names: – Maximum length? – Are names case sensitive? – Are special words reserved words or keywords? 5.2.2 Name Forms A name is a string of characters used to identify some entity in a program. Length – If too short, they cannot be connotative – Language examples: . FORTRAN I: maximum 6 . COBOL: maximum 30 . C99: no limit but only the first 63 are significant; also, external names are limited to a maximum of 31 . C# and Java: no limit, and all characters are significant . C++: no limit, but implementers often impose a length limitation because they do not want the symbol table in which identifiers are stored during compilation to be too large and also to simplify the maintenance of that table.
    [Show full text]
  • 7. Functions in PHP – II
    7. Functions in PHP – II Scope of variables in Function Scope of variable is the part of PHP script where the variable can be accessed or used. PHP supports three different scopes for a variable. These scopes are 1. Local 2. Global 3. Static A variable declared within the function has local scope. That means this variable is only used within the function body. This variable is not used outside the function. To demonstrate the concept, let us take an example. // local variable scope function localscope() { $var = 5; //local scope echo '<br> The value of $var inside the function is: '. $var; } localscope(); // call the function // using $var outside the function will generate an error echo '<br> The value of $var inside the function is: '. $var; The output will be: The value of $var inside the function is: 5 ( ! ) Notice: Undefined variable: var in H:\wamp\www\PathshalaWAD\function\function localscope demo.php on line 12 Call Stack # Time Memory Function Location 1 0.0003 240416 {main}( ) ..\function localscope demo.php:0 The value of $var inside the function is: Page 1 of 7 If a variable is defined outside of the function, then the variable scope is global. By default, a global scope variable is only available to code that runs at global level. That means, it is not available inside a function. Following example demonstrate it. <?php //variable scope is global $globalscope = 20; // local variable scope function localscope() { echo '<br> The value of global scope variable is :'.$globalscope; } localscope(); // call the function // using $var outside the function will generate an error echo '<br> The value of $globalscope outside the function is: '.
    [Show full text]
  • Object Lifetimes In
    Object Lifetimes in Tcl - Uses, Misuses, Limitations By Phil Brooks - Mentor – A Siemens Corporation Presented at the 25 nd annual Tcl/Tk conference, Houston Texas, November 2018 Mentor – A Siemens Corporation 8005 Boeckman Road Wilsonville, Oregon 97070 [email protected] Abstract: The management of the lifetime of an object in Tcl presents a number of unique challenges. In the C++ world, the technique of Resource Allocation is Initialization (RAII) is commonly used to control the lifetime of certain objects. With this technique, an object on the call stack is used to insure proper cleanup of a resource. When the object goes out of scope, the resource is released. It presents a low overhead mechanism for a garbage collection like facility without the complication of more complete garbage collection systems. Tcl doesn't have a similar direct capability, and the need for it has resulted in two techniques that are commonly used to substitute for the capability. The techniques are: 1) Use of the trace command to catch unset of a variable. 2) Mis-use of the lifetime of a Tcl_Obj created with Tcl_NewObj. Each of these techniques has drawbacks. The primary issue with the trace technique is that it requires the user of an object to arrange for explicit destruction of the object. This makes the interface more error prone. The mis-use of lifetime of a Tcl_Obj is subject to premature cleanup of the resource if the object is shimmered to a string for any reason. This paper surveys these lifetime management patterns and demonstrates the use of a new user level technique for lifetime management.
    [Show full text]
  • Declare Function Inside a Function Python
    Declare Function Inside A Function Python Transisthmian and praetorian Wye never ensphere helter-skelter when Shawn lord his nightshade. Larboard Hal rumors her dizziesacapnia very so encouragingly actinally. that Colbert aurifies very inferentially. Kenyan Tad reframes her botts so irefully that Etienne Closures prove to it efficient way something we took few functions in our code. Hope you have any mutable object. Calling Functions from Other Files Problem Solving with Python. What embassy your website look like? Then you can declare any result of a million developers have been loaded? The coach who asked this gas has marked it as solved. We focus group functions together can a Python module see modules and it this way lead our. What are Lambda Functions and How to Use Them? It working so art the result variable is only accessible inside the function in. Variables inside python node, learn more detail, regardless of instances of a program demonstrates it. The python function inside another, which start here, and beginners start out. Get code examples like python define a function within a function instantly right anytime your google search results with the Grepper Chrome. The function by replacing it contains one function start here are discussed: how do not provide extremely cost efficient as their name? How to the page helpful for case it requires you can declare python data science. Each item from the python function has arbitrary length arguments must first, but are only the output is simply the function to. We declare their perfomance varies with the gathered arguments using a wrapped the arguments does the computed fahrenheit to declare function inside a function python? List of python can declare a function inside a million other functions we declare function inside a function python.
    [Show full text]
  • Perl Baseless Myths & Startling Realities
    http://xkcd.com/224/ 1 Perl Baseless Myths & Startling Realities by Tim Bunce, February 2008 2 Parrot and Perl 6 portion incomplete due to lack of time (not lack of myths!) Realities - I'm positive about Perl Not negative about other languages - Pick any language well suited to the task - Good developers are always most important, whatever language is used 3 DISPEL myths UPDATE about perl Who am I? - Tim Bunce - Author of the Perl DBI module - Using Perl since 1991 - Involved in the development of Perl 5 - “Pumpkin” for 5.4.x maintenance releases - http://blog.timbunce.org 4 Perl 5.4.x 1997-1998 Living on the west coast of Ireland ~ Myths ~ 5 http://www.bleaklow.com/blog/2003/08/new_perl_6_book_announced.html ~ Myths ~ - Perl is dead - Perl is hard to read / test / maintain - Perl 6 is killing Perl 5 6 Another myth: Perl is slow: http://www.tbray.org/ongoing/When/200x/2007/10/30/WF-Results ~ Myths ~ - Perl is dead - Perl is hard to read / test / maintain - Perl 6 is killing Perl 5 7 Perl 5 - Perl 5 isn’t the new kid on the block - Perl is 21 years old - Perl 5 is 14 years old - A mature language with a mature culture 8 How many times Microsoft has changed developer technologies in the last 14 years... 9 10 You can guess where thatʼs leading... From “The State of the Onion 10” by Larry Wall, 2006 http://www.perl.com/pub/a/2006/09/21/onion.html?page=3 Buzz != Jobs - Perl5 hasn’t been generating buzz recently - It’s just getting on with the job - Lots of jobs - just not all in web development 11 Web developers tend to have a narrow focus.
    [Show full text]
  • Chapter 5. Using Tcl/Tk
    The Almagest 5-1 Chapter 5. Using Tcl/Tk Authors: Edward A. Lee Other Contributors: Brian L. Evans Wei-Jen Huang Alan Kamas Kennard White 5.1 Introduction Tcl is an interpreted “tool command language” designed by John Ousterhout while at UC Berkeley. Tk is an associated X window toolkit. Both have been integrated into Ptolemy. Parts of the graphical user interface and all of the textual interpreter ptcl are designed using them. Several of the stars in the standard star library also use Tcl/Tk. This chapter explains how to use the most basic of these stars, TclScript, as well how to design such stars from scratch. It is possible to define very sophisticated, totally customized user interfaces using this mechanism. In this chapter, we assume the reader is familiar with the Tcl language. Documentation is provided along with the Ptolemy distribution in the $PTOLEMY/tcltk/itcl/man direc- tory in Unix man page format. HTML format documentation is available from the other.src tar file in $PTOLEMY/src/tcltk. Up-to-date documentation and software releases are available by on the SunScript web page at http://www.sunscript.com. There is also a newsgroup called comp.lang.tcl. This news group accumulates a list of frequently asked questions about Tcl which is available http://www.teraform.com/%7Elvirden/tcl-faq/. The principal use of Tcl/Tk in Ptolemy is to customize the user interface. Stars can be created that interact with the user in specialized ways, by creating customized displays or by soliciting graphical inputs. 5.2 Writing Tcl/Tk scripts for the TclScript star Several of the domains in Ptolemy have a star called TclScript.
    [Show full text]
  • Linux Lunacy V & Perl Whirl
    SPEAKERS Linux Lunacy V Nicholas Clark Scott Collins & Perl Whirl ’05 Mark Jason Dominus Andrew Dunstan Running Concurrently brian d foy Jon “maddog” Hall Southwestern Caribbean Andrew Morton OCTOBER 2ND TO 9TH, 2005 Ken Pugh Allison Randal Linux Lunacy V and Perl Whirl ’05 run concurrently. Attendees can mix and match, choosing courses from Randal Schwartz both conferences. Doc Searls Ted Ts’o Larry Wall Michael Warfield DAY PORT ARRIVE DEPART CONFERENCE SESSIONS Sunday, Oct 2 Tampa, Florida — 4:00pm 7:15pm, Bon Voyage Party Monday, Oct 3 Cruising The Caribbean — — 8:30am – 5:00pm Tuesday, Oct 4 Grand Cayman 7:00am 4:00pm 4:00pm – 7:30pm Wednesday, Oct 5 Costa Maya, Mexico 10:00am 6:00pm 6:00pm – 7:30pm Thursday, Oct 6 Cozumel, Mexico 7:00am 6:00pm 6:00pm – 7:30pm Friday, Oct 7 Belize City, Belize 7:30am 4:30pm 4:30pm – 8:00pm Saturday, Oct 8 Cruising The Caribbean — — 8:30am – 5:00pm Sunday, Oct 9 Tampa, Florida 8:00am — Perl Whirl ’05 and Linux Lunacy V Perl Whirl ’05 are running concurrently. Attendees can mix and match, choosing courses Seminars at a Glance from both conferences. You may choose any combination Regular Expression Mastery (half day) Programming with Iterators and Generators of full-, half-, or quarter-day seminars Speaker: Mark Jason Dominus Speaker: Mark Jason Dominus (half day) for a total of two-and-one-half Almost everyone has written a regex that failed Sometimes you’ll write a function that takes too (2.5) days’ worth of sessions. The to match something they wanted it to, or that long to run because it produces too much useful conference fee is $995 and includes matched something they thought it shouldn’t, and information.
    [Show full text]
  • When Geeks Cruise
    COMMUNITY Geek Cruise: Linux Lunacy Linux Lunacy, Perl Whirl, MySQL Swell: Open Source technologists on board When Geeks Cruise If you are on one of those huge cruising ships and, instead of middle-aged ladies sipping cocktails, you spot a bunch of T-shirt touting, nerdy looking guys hacking on their notebooks in the lounges, chances are you are witnessing a “Geek Cruise”. BY ULRICH WOLF eil Baumann, of Palo Alto, Cali- and practical tips on application develop- The dedicated Linux track comprised a fornia, has been organizing geek ment – not only for Perl developers but meager spattering of six lectures, and Ncruises since 1999 (http://www. for anyone interested in programming. though there was something to suit geekcruises.com/), Neil always finds everyone’s taste, the whole thing tended enough open source and programming Perl: Present and to lack detail. Ted T’so spent a long time celebrities to hold sessions on Linux, (Distant?) Future talking about the Ext2 and Ext3 file sys- Perl, PHP and other topics dear to geeks. In contrast, Allison Randal’s tutorials on tems, criticizing ReiserFS along the way, Parrot Assembler and Perl6 features were but had very little to say about network Open Source Celebs hardcore. Thank goodness Larry Wall file systems, an increasingly vital topic. on the Med summed up all the major details on Perl6 Developers were treated to a lecture on I was lucky enough to get on board the in a brilliant lecture that was rich with developing shared libraries, and admins first Geek Cruise on the Mediterranean, metaphors and bursting with informa- enjoyed sessions on Samba and hetero- scaring the nerds to death with my tion.
    [Show full text]
  • Coding 101: Learn Ruby in 15 Minutes Visit
    Coding 101: Learn Ruby in 15 minutes Visit www.makers.tech 1 Contents 2 Contents 10 Challenge 3 3 About us 11 Defining Methods 4 Installing Ruby 12 Challenge 4 4 Checking you’ve got Ruby 12 Challenge 5 5 Method calls 12 Challenge 6 5 Variables 13 Arrays 6 Truth and Falsehood 14 Hashes 7 Strings, objects and Methods 14 Challenge 7 8 Challenge 1 15 Iterations 8 Challenge 2 16 Challenge 8 9 Method Chaining 16 Challenge 9 10 Conditionals 18 Extra Challenges 2 About Us At Makers, we are creating a new generation of tech talent who are skilled and ready for the changing world of work. We are inspired by the idea of discovering and unlocking potential in people for the benefit of 21st century business and society. We believe in alternative ways to learn how to code, how to be ready for work and how to be of value to an organisation. At our core, Makers combines tech education with employment possibilities that transform lives. Our intensive four-month program (which includes a month-long PreCourse) sets you up to become a high quality professional software engineer. Makers is the only coding bootcamp with 5 years experience training software developers remotely. Your virtual experience will be exactly the same as Makers on-site, just delivered differently. If you’d like to learn more, check out www.makers.tech. 3 Installing Checking Ruby you’ve got Ruby You’ll be happy to know that Ruby comes preinstalled on all Apple computers. However we can’t simply use the system defaults - just in case we mess something up! Open the terminal on your computer and then type in If you’ve got your laptop set up already you can skip this section.
    [Show full text]
  • Function Components and Arguments Passing in Cpp
    FUNCTION COMPONENTS AND ARGUMENTS PASSING IN CPP The General Form of a Function The general form of a function is ret-type function-name(parameter list) { body of the function } The ret-type specifies the type of data that the function returns.Afunction may return any type of data except an array. The parameter list is a comma-separated list of variable names and their associated types that receive the values of the arguments when the function is called.Afunction may be without parameters, in which case the parameter list is empty. However, even if there are no parameters, the parentheses are still required. In variable declarations, you can declare many variables to be of a common type by using a comma- separated list of variable names. In contrast, all function parameters must be declared individually, each including both the type and name. That is, the parameter declaration list for a function takes this general form: f(type varname1, type varname2, . , type varnameN) For example, here are correct and incorrect function parameter declarations: f(int i, int k, int j) /* correct */ f(int i, k, float j) /* incorrect */ Scope Rules of Functions The scope rules of a language are the rules that govern whether a piece of code knows about or has access to another piece of code or data. Each function is a discrete block of code. Afunction's code is private to that function and cannot be accessed by any statement in any other function except through a call to that function. (For instance, you cannot use goto to jump into the middle of another function.) The code that constitutes the body of a function is hidden from the rest of the program and, unless it uses global variables or data, it can neither affect nor be affected by other parts of the program.
    [Show full text]
  • Subprograms: Local Variables
    Subprograms: Local Variables ICS312 Machine-Level and Systems Programming Henri Casanova ([email protected]) Local Variables in Subprograms In all the examples we have seen so far, the subprograms were able to do their work using only registers But sometimes, a subprogram’s needs are beyond the set of available registers and some data must be kept in memory Just think of all subprograms you wrote that used more than 6 local variables (EAX, EBX, ECX, EDX, ESI, EDI) One possibility could be to declare a small .bss segment for each subprogram, to reserve memory space for all local variables Drawback #1: memory waste This reserved memory consumes memory space for the entire duration of the execution even if the subprogram is only active for a tiny fraction of the execution time (or never!) Drawback #2: subprograms are not reentrant Re-entrant subprogram A subprogram is active if it has been called but the RET instruction hasn’t been executed yet A subprogram is reentrant if it can be called from anywhere in the program This implies that the program can call itself, directly or indirectly, which enables recursion e.g., f calls g, which calls h, which calls f At a given time, two or more instances of a subprogram can be active Two or more activation records for this subprogram on the stack If we store the local variables of a subprogram in the .bss segment, then there can only be one activation! Otherwise activation #2 could corrupt the local variables of the activation #1 Therefore, with our current scheme for storing local
    [Show full text]
  • Minimal Perl for UNIX and Linux People
    Minimal Perl For UNIX and Linux People BY TIM MAHER MANNING Greenwich (74° w. long.) For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special Sales Department Manning Publications Co. Cherokee Station PO Box 20386 Fax: (609) 877-8256 New York, NY 10021 email: [email protected] ©2007 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Manning Publications Co. Copyeditor: Tiffany Taylor 209 Bruce Park Avenue Typesetters: Denis Dalinnik, Dottie Marsico Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN 1-932394-50-8 Printed in the United States of America 12345678910–VHG–1009080706 To Yeshe Dolma Sherpa, whose fortitude, endurance, and many sacrifices made this book possible. To my parents, Gloria Grady Washington and William N. Maher, who indulged my early interests in literature. To my limbic system, with gratitude for all the good times we’ve had together.
    [Show full text]