Modern Perl 2011-2012 Edition

Total Page:16

File Type:pdf, Size:1020Kb

Modern Perl 2011-2012 Edition Modern Perl 2011-2012 edition chromatic Modern Perl 2011-2012 edition Copyright © 2010-2012 chromatic Editor: Shane Warden Logo design: Devin Muldoon Cover design: Allison Randal, chromatic, and Jeffrey Martin ISBN-10: 0-9779201-7-8 ISBN-13: 978-0-9779201-7-4 Published by Onyx Neon Press, http://www.onyxneon.com/. The Onyx Neon logo is a trademark of Onyx Neon, Inc. Onyx Neon typesets books with free software, especially Ubuntu GNU/Linux, Perl 5, PseudoPod, and LATEX. Many thanks to the contributors who make these and other projects possible. 2010 - 2011 Edition October 2010 2011 - 2012 Edition January 2012 Electronic versions of this book are available from http://onyxneon.com/books/modern_perl/, and the companion website is http://modernperlbooks.com/. Please share with your friends and colleagues. Thanks for reading! Contents Running Modern Perl . .i Credits . ii Preface i 1 The Perl Philosophy 1 Perldoc . .1 Expressivity . .2 Context ..........................................................3 Void, Scalar, and List Context . .4 Numeric, String, and Boolean Context . .5 Implicit Ideas . .5 The Default Scalar Variable . .5 The Default Array Variables . .7 2 Perl and Its Community 9 TheCPAN.........................................................9 CPAN Management Tools . 10 Community Sites . 11 Development Sites . 11 Events........................................................... 11 IRC ............................................................ 12 3 The Perl Language 13 Names........................................................... 13 Variable Names and Sigils . 14 Namespaces . 14 Variables . 15 Variable Scopes . 15 Variable Sigils . 15 Anonymous Variables . 16 Variables, Types, and Coercion . 16 Values........................................................... 16 Strings . 16 Unicode and Strings . 18 Character Encodings . 19 Unicode in Your Filehandles . 19 Unicode in Your Data . 20 Unicode in Your Programs . 20 Implicit Conversion . 20 Numbers . 22 Undef........................................................ 22 The Empty List . 23 Lists......................................................... 23 Control Flow . 24 Branching Directives . 24 The Ternary Conditional Operator . 27 Short Circuiting . 27 Context for Conditional Directives . 28 Looping Directives . 28 Iteration and Aliasing . 30 Iteration and Scoping . 30 The C-Style For Loop . 31 While and Until . 32 Loops within Loops . 34 Loop Control . 35 Continue . 36 Given/When . 36 Tailcalls . 38 Scalars . 39 Scalars and Types . 39 Arrays........................................................... 40 Array Elements . 40 Array Assignment . 41 Array Operations . 42 Array Slices . 43 Arrays and Context . 44 Array Interpolation . 44 Hashes........................................................... 45 Declaring Hashes . 45 Hash Indexing . 46 Hash Key Existence . 47 Accessing Hash Keys and Values . 48 Hash Slices . 48 The Empty Hash . 49 Hash Idioms . 50 Locking Hashes . 51 Coercion . 51 Boolean Coercion . 52 String Coercion . 52 Numeric Coercion . 52 Reference Coercion . 52 Cached Coercions . ..
Recommended publications
  • 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]
  • A Call-By-Need Lambda Calculus
    A CallByNeed Lamb da Calculus Zena M Ariola Matthias Fel leisen Computer Information Science Department Department of Computer Science University of Oregon Rice University Eugene Oregon Houston Texas John Maraist and Martin Odersky Philip Wad ler Institut fur Programmstrukturen Department of Computing Science Universitat Karlsruhe UniversityofGlasgow Karlsruhe Germany Glasgow Scotland Abstract arguments value when it is rst evaluated More pre cisely lazy languages only reduce an argument if the The mismatchbetween the op erational semantics of the value of the corresp onding formal parameter is needed lamb da calculus and the actual b ehavior of implemen for the evaluation of the pro cedure b o dy Moreover af tations is a ma jor obstacle for compiler writers They ter reducing the argument the evaluator will remember cannot explain the b ehavior of their evaluator in terms the resulting value for future references to that formal of source level syntax and they cannot easily com parameter This technique of evaluating pro cedure pa pare distinct implementations of dierent lazy strate rameters is called cal lbyneed or lazy evaluation gies In this pap er we derive an equational characteri A simple observation justies callbyneed the re zation of callbyneed and prove it correct with resp ect sult of reducing an expression if any is indistinguish to the original lamb da calculus The theory is a strictly able from the expression itself in all p ossible contexts smaller theory than the lamb da calculus Immediate Some implementations attempt
    [Show full text]
  • NU-Prolog Reference Manual
    NU-Prolog Reference Manual Version 1.5.24 edited by James A. Thom & Justin Zobel Technical Report 86/10 Machine Intelligence Project Department of Computer Science University of Melbourne (Revised November 1990) Copyright 1986, 1987, 1988, Machine Intelligence Project, The University of Melbourne. All rights reserved. The Technical Report edition of this publication is given away free subject to the condition that it shall not, by the way of trade or otherwise, be lent, resold, hired out, or otherwise circulated, without the prior consent of the Machine Intelligence Project at the University of Melbourne, in any form or cover other than that in which it is published and without a similar condition including this condition being imposed on the subsequent user. The Machine Intelligence Project makes no representations or warranties with respect to the contents of this document and specifically disclaims any implied warranties of merchantability or fitness for any particular purpose. Furthermore, the Machine Intelligence Project reserves the right to revise this document and to make changes from time to time in its content without being obligated to notify any person or body of such revisions or changes. The usual codicil that no part of this publication may be reproduced, stored in a retrieval system, used for wrapping fish, or transmitted, in any form or by any means, electronic, mechanical, photocopying, paper dart, recording, or otherwise, without someone's express permission, is not imposed. Enquiries relating to the acquisition of NU-Prolog should be made to NU-Prolog Distribution Manager Machine Intelligence Project Department of Computer Science The University of Melbourne Parkville, Victoria 3052 Australia Telephone: (03) 344 5229.
    [Show full text]
  • Variable-Arity Generic Interfaces
    Variable-Arity Generic Interfaces T. Stephen Strickland, Richard Cobbe, and Matthias Felleisen College of Computer and Information Science Northeastern University Boston, MA 02115 [email protected] Abstract. Many programming languages provide variable-arity func- tions. Such functions consume a fixed number of required arguments plus an unspecified number of \rest arguments." The C++ standardiza- tion committee has recently lifted this flexibility from terms to types with the adoption of a proposal for variable-arity templates. In this paper we propose an extension of Java with variable-arity interfaces. We present some programming examples that can benefit from variable-arity generic interfaces in Java; a type-safe model of such a language; and a reduction to the core language. 1 Introduction In April of 2007 the C++ standardization committee adopted Gregor and J¨arvi's proposal [1] for variable-length type arguments in class templates, which pre- sented the idea and its implementation but did not include a formal model or soundness proof. As a result, the relevant constructs will appear in the upcom- ing C++09 draft. Demand for this feature is not limited to C++, however. David Hall submitted a request for variable-arity type parameters for classes to Sun in 2005 [2]. For an illustration of the idea, consider the remarks on first-class functions in Scala [3] from the language's homepage. There it says that \every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying." To achieve this integration of objects and closures, Scala's standard library pre-defines ten interfaces (traits) for function types, which we show here in Java-like syntax: interface Function0<Result> { Result apply(); } interface Function1<Arg1,Result> { Result apply(Arg1 a1); } interface Function2<Arg1,Arg2,Result> { Result apply(Arg1 a1, Arg2 a2); } ..
    [Show full text]
  • Perl 6 Der Heilige Gral
    Perl 6 Der heilige Gral Suche nach dem ver... 19. Juli 2000 Perl 6 Design ● Apokalypsen ● Exegesen ● Synopsen Perl 6 Design ● Apokalypsen ● Exegesen ● Synopsen Perl 6 Design ● Apokalypsen ● Exegesen ● Synopsen ● wiki.perl-community.de/bin/view/Wissensbasis/PerlTafel ● http://perl-6.de/ Perl 6 Design ● p6l ([email protected]) ● #perl6 (irc.freenode.org/perl6) Perl 6 Design ● p6l ([email protected]) ● #perl6 (irc.freenode.org/perl6) ● Larry Wall, Damian Conway, Patrick R. Michaud, Allison Randal, chromatic Perl 6 Design ● p6l ([email protected]) ● #perl6 (irc.freenode.org/perl6) ● Larry Wall, Damian Conway, Patrick R. Michaud, Allison Randal, chromatic ● Dan Sugalski, Luke Palmer, Audrey Tang Parrot 1. April 2001 Parrot Code #copy stdin to stdout, except for lines starting with # while left_angle_right_angle: if dollar_underscore[0] =eq= "#": continue_next; } print dollar_underscore; } Parrot ● VM (Virtuelle Maschine) Parrot ● VM (Virtuelle Maschine) ● Software - CPU Parrot ● VM (Virtuelle Maschine) ● native/magische Register Parrot ● VM (Virtuelle Maschine) ● native/magische Register ● Continuations Parrot ● VM (Virtuelle Maschine) ● native/magische Register ● Continuations ● Dan Sugalski Parrot ● VM (Virtuelle Maschine) ● native/magische Register ● Continuations ● Dan Sugalski ● Mastermind Parrot ● VM (Virtuelle Maschine) ● native/magische Register ● Continuations ● Dan Sugalski ● Mastermind - Einzelkämpfer Parrot ● VM (Virtuelle Maschine) ● native/magische Register ● Continuations ● Dan Sugalski ● Allison Randal Allison Randal ● Exchefin der Perl Foundation Allison Randal ● Exchefin der Perl Foundation ● Parrot Leiterin Allison Randal ● Exchefin der Perl Foundation ● Parrot Leiterin ● Parrot Hacker Allison Randal ● Exchefin der Perl Foundation ● Parrot Leiterin ● Parrot Hacker ● Specschreiber Allison Randal ● Exchefin der Perl Foundation ● Parrot Leiterin ● Parrot Hacker ● Specschreiber ● TGE / Punie Parrot's Sprachen Parrot's Sprachen ● .pbc Parrot bytecode Parrot's Sprachen ● .pbc Parrot bytecode ● .pasm P.
    [Show full text]
  • Small Hitting-Sets for Tiny Arithmetic Circuits Or: How to Turn Bad Designs Into Good
    Electronic Colloquium on Computational Complexity, Report No. 35 (2017) Small hitting-sets for tiny arithmetic circuits or: How to turn bad designs into good Manindra Agrawal ∗ Michael Forbes† Sumanta Ghosh ‡ Nitin Saxena § Abstract Research in the last decade has shown that to prove lower bounds or to derandomize polynomial identity testing (PIT) for general arithmetic circuits it suffices to solve these questions for restricted circuits. In this work, we study the smallest possibly restricted class of circuits, in particular depth-4 circuits, which would yield such results for general circuits (that is, the complexity class VP). We show that if we can design poly(s)-time hitting-sets for Σ ∧a ΣΠO(log s) circuits of size s, where a = ω(1) is arbitrarily small and the number of variables, or arity n, is O(log s), then we can derandomize blackbox PIT for general circuits in quasipolynomial time. Further, this establishes that either E6⊆#P/poly or that VP6=VNP. We call the former model tiny diagonal depth-4. Note that these are merely polynomials with arity O(log s) and degree ω(log s). In fact, we show that one only needs a poly(s)-time hitting-set against individual-degree a′ = ω(1) polynomials that are computable by a size-s arity-(log s) ΣΠΣ circuit (note: Π fanin may be s). Alternatively, we claim that, to understand VP one only needs to find hitting-sets, for depth-3, that have a small parameterized complexity. Another tiny family of interest is when we restrict the arity n = ω(1) to be arbitrarily small.
    [Show full text]
  • Making a Faster Curry with Extensional Types
    Making a Faster Curry with Extensional Types Paul Downen Simon Peyton Jones Zachary Sullivan Microsoft Research Zena M. Ariola Cambridge, UK University of Oregon [email protected] Eugene, Oregon, USA [email protected] [email protected] [email protected] Abstract 1 Introduction Curried functions apparently take one argument at a time, Consider these two function definitions: which is slow. So optimizing compilers for higher-order lan- guages invariably have some mechanism for working around f1 = λx: let z = h x x in λy:e y z currying by passing several arguments at once, as many as f = λx:λy: let z = h x x in e y z the function can handle, which is known as its arity. But 2 such mechanisms are often ad-hoc, and do not work at all in higher-order functions. We show how extensional, call- It is highly desirable for an optimizing compiler to η ex- by-name functions have the correct behavior for directly pand f1 into f2. The function f1 takes only a single argu- expressing the arity of curried functions. And these exten- ment before returning a heap-allocated function closure; sional functions can stand side-by-side with functions native then that closure must subsequently be called by passing the to practical programming languages, which do not use call- second argument. In contrast, f2 can take both arguments by-name evaluation. Integrating call-by-name with other at once, without constructing an intermediate closure, and evaluation strategies in the same intermediate language ex- this can make a huge difference to run-time performance in presses the arity of a function in its type and gives a princi- practice [Marlow and Peyton Jones 2004].
    [Show full text]
  • Lambda-Calculus Types and Models
    Jean-Louis Krivine LAMBDA-CALCULUS TYPES AND MODELS Translated from french by René Cori To my daughter Contents Introduction5 1 Substitution and beta-conversion7 Simple substitution ..............................8 Alpha-equivalence and substitution ..................... 12 Beta-conversion ................................ 18 Eta-conversion ................................. 24 2 Representation of recursive functions 29 Head normal forms .............................. 29 Representable functions ............................ 31 Fixed point combinators ........................... 34 The second fixed point theorem ....................... 37 3 Intersection type systems 41 System D­ ................................... 41 System D .................................... 50 Typings for normal terms ........................... 54 4 Normalization and standardization 61 Typings for normalizable terms ........................ 61 Strong normalization ............................. 68 ¯I-reduction ................................. 70 The ¸I-calculus ................................ 72 ¯´-reduction ................................. 74 The finite developments theorem ....................... 77 The standardization theorem ......................... 81 5 The Böhm theorem 87 3 4 CONTENTS 6 Combinatory logic 95 Combinatory algebras ............................. 95 Extensionality axioms ............................. 98 Curry’s equations ............................... 101 Translation of ¸-calculus ........................... 105 7 Models of lambda-calculus 111 Functional
    [Show full text]
  • Decompositions of Functions Based on Arity
    DECOMPOSITIONS OF FUNCTIONS BASED ON ARITY GAP MIGUEL COUCEIRO, ERKKO LEHTONEN, AND TAMAS´ WALDHAUSER1 Abstract. We study the arity gap of functions of several variables defined on an arbitrary set A and valued in another set B. The arity gap of such a function is the minimum decrease in the number of essential variables when variables are identified. We establish a complete classification of functions according to their arity gap, extending existing results for finite functions. This classification is refined when the codomain B has a group structure, by providing unique decompositions into sums of functions of a prescribed form. As an application of the unique decompositions, in the case of finite sets we count, for each n and p, the number of n-ary functions that depend on all of their variables and have arity gap p. 1. Introduction Essential variables of functions have been investigated in multiple-valued logic and computer science, especially, concerning the distribution of values of functions whose variables are all essential (see, e.g., [9, 16, 22]), the process of substituting constants for variables (see, e.g., [2, 3, 14, 16, 18]), and the process of substituting variables for variables (see, e.g., [5, 10, 16, 21]). The latter line of study goes back to the 1963 paper by Salomaa [16] who consid- ered the following problem: How does identification of variables affect the number of essential variables of a given function? The minimum decrease in the number of essential variables of a function f : An → B (n ≥ 2) which depends on all of its variables is called the arity gap of f.
    [Show full text]
  • Index Images Download 2006 News Crack Serial Warez Full 12 Contact
    index images download 2006 news crack serial warez full 12 contact about search spacer privacy 11 logo blog new 10 cgi-bin faq rss home img default 2005 products sitemap archives 1 09 links 01 08 06 2 07 login articles support 05 keygen article 04 03 help events archive 02 register en forum software downloads 3 security 13 category 4 content 14 main 15 press media templates services icons resources info profile 16 2004 18 docs contactus files features html 20 21 5 22 page 6 misc 19 partners 24 terms 2007 23 17 i 27 top 26 9 legal 30 banners xml 29 28 7 tools projects 25 0 user feed themes linux forums jobs business 8 video email books banner reviews view graphics research feedback pdf print ads modules 2003 company blank pub games copyright common site comments people aboutus product sports logos buttons english story image uploads 31 subscribe blogs atom gallery newsletter stats careers music pages publications technology calendar stories photos papers community data history arrow submit www s web library wiki header education go internet b in advertise spam a nav mail users Images members topics disclaimer store clear feeds c awards 2002 Default general pics dir signup solutions map News public doc de weblog index2 shop contacts fr homepage travel button pixel list viewtopic documents overview tips adclick contact_us movies wp-content catalog us p staff hardware wireless global screenshots apps online version directory mobile other advertising tech welcome admin t policy faqs link 2001 training releases space member static join health
    [Show full text]
  • Pragmaticperl-Interviews-A4.Pdf
    Pragmatic Perl Interviews pragmaticperl.com 2013—2015 Editor and interviewer: Viacheslav Tykhanovskyi Covers: Marko Ivanyk Revision: 2018-03-02 11:22 © Pragmatic Perl Contents 1 Preface .......................................... 1 2 Alexis Sukrieh (April 2013) ............................... 2 3 Sawyer X (May 2013) .................................. 10 4 Stevan Little (September 2013) ............................. 17 5 chromatic (October 2013) ................................ 22 6 Marc Lehmann (November 2013) ............................ 29 7 Tokuhiro Matsuno (January 2014) ........................... 46 8 Randal Schwartz (February 2014) ........................... 53 9 Christian Walde (May 2014) .............................. 56 10 Florian Ragwitz (rafl) (June 2014) ........................... 62 11 Curtis “Ovid” Poe (September 2014) .......................... 70 12 Leon Timmermans (October 2014) ........................... 77 13 Olaf Alders (December 2014) .............................. 81 14 Ricardo Signes (January 2015) ............................. 87 15 Neil Bowers (February 2015) .............................. 94 16 Renée Bäcker (June 2015) ................................ 102 17 David Golden (July 2015) ................................ 109 18 Philippe Bruhat (Book) (August 2015) . 115 19 Author .......................................... 123 i Preface 1 Preface Hello there! You have downloaded a compilation of interviews done with Perl pro- grammers in Pragmatic Perl journal from 2013 to 2015. Since the journal itself is in Russian
    [Show full text]
  • SM User Guide
    Oracle® Communications Tekelec Virtual Operating Environment Licensing Information User Manual Release 3.5 E93070-01 November 2017 Copyright ©2010, 2017 Oracle and/or its affiliates. All rights reserved. This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, then the following notice is applicable: U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are "commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs. No other rights are granted to the U.S.
    [Show full text]