CS 105 Perl: Completing the Toolbox
|
|
- Jordan Russell
- 6 years ago
- Views:
Transcription
1 CS 105 Perl: Completing the Toolbox March 4, 2013
2 Agenda autodie with open Inspecting scalars perl -c Unary coercion Topicalization ~~ Unique list idiom Schwartzian Transform Using // for defaults and memoization Code references and closures
3 open review We ve covered opening files for reading and writing: open my $reader, <, "file" or die... open my $writer, >, "output" or die... The names of the file handles are not special; they are merely chosen for pedagogical value.
4 open and pipes open can be used to run programs that we can read from via pipes or to run programs that we can write to via pipes. # read from another program open my $reader, -, "/path/to/command" or die... # write to another program open my $writer, -, "/path/to/command" or die... To supplement perldoc -f open, consider perldoc perlopentut for more complete coverage of the power of open with good explanations.
5 autodie Checking the return values of every open can be very tedious and repetitive. The autodie pragma handles this responsibility automatically. use autodie; open my $f, <, "filename"; # this is ok... # because autodie will... # automatically die in case of failure. autodie is similar to warnings in that it is lexical with many knobs you can adjust. See perldoc autodie.
6 Filehandle references are handy Since Perl is reference counted, we can depend on variable scoping to automatically close files. use IO::Handle; use autodie; { open my $file, >, outputfile ; $file->say( Blarg, I say. ); #... } # $file out of scope and therefore closed! Note that to use the IO::Handle methods on the file object, you will need to load that module.
7 Another cute open feature Perl allows a filehandle to actually refer to a scalar (e.g. for output buffering or reading from slurped data). use IO::Handle; use autodie; our $dump; { open my $file, >, \$dump; $file->say( Blarg into a scalar ); #... } # use $dump at some point...
8 What type of reference is this? Given some arbitrary scalar, how can you tell if it is a reference? What type of a reference is it? Is it an object (a blessed reference)? Is it some other type of reference? Perl provides the ref function to help answer these questions. ref will return false if the scalar is not a reference. If the reference is blessed, ref will return the package (i.e. class) name. Otherwise, the type of reference will be returned (as a string): e.g. SCALAR, ARRAY, and so on (see the documentation for further details).
9 Is this reference blessed? The Scalar::Util module (part of the Perl core; i.e. it comes with Perl) includes the function blessed. use Scalar::Util qw(blessed); $obj = bless [], "Foo"; $class = blessed $obj; # "Foo" blessed will return undef if the scalar is not a blessed reference (e.g. an unblessed reference or some other scalar value).
10 reftype You might want to know what type of reference is in a scalar regardless of whether it s blessed or not. Scalar::Util has a function for this, too: reftype.
11 perl -c You can use perl -c to do a syntax check on your program without running it. % perl -c broken-script syntax error at broken-script line 6, near "print" broken-script had compilation errors. %
12 Unary coercions # numeric my $number = 0 + $whatever; # string my $string =. $whatever; # boolean my $bool =!! $whatever;
13 Unary coercion in hash key brackets $words{lc}++; # lc. oops. $words{+lc}++; # evaluate lc (function!) # normally not necessary $words{$obj->method( foo ) - 10} = baz();
14 Truth Trickery Sometimes we would like a zero value to still be interpreted as true in a boolean context (perhaps in the sense of success ). These values evaluate to 0 in a numeric context, but aren t one of the five false values. $a = 0e0 ; $b = 0e ; $c = 0.0 ; $d = 0 but true ; # chatty
15 Using given for topicalization given implicitly sets $_ to its argument. given ($important) { s/_+//g; say; } This code won t modify $important, but it allows us to do something with it with both brevity and safety.
16 given-less when You can use the magic of when (~~ and more) in a for loop, too! my $count; my $v = 0; for (@a) { when($v) { ++$v } say "Nope, not that one."; } say "Made it to $v"; This only works when not specifying an iteration variable (i.e. using default $_). The when block has an implicit next at the end.
17 ~~ is the operator behind the curtain Many of you have already used ~~ without realizing it! In a given / when construct, the left-hand operand is provided by given and the right-hand operand is provided by the when.
18 Explicit use of ~~ ~~ is the smart match operator (new in Perl 5.10). It is a kitchen-sink style polymorphic operator that determines whether the two operands match in some dwimmy way. Here are some of its default behaviors: $a ~~ undef # true if $a is undef $a ~~ /$b/ # same as ~~ /$b/ # grep %a ~~ /$b/ # grep /$b/, keys %a $a # grep { $a ~~ $_ %a ~~ %b # hash keys identical This is just a small subset of all the behaviors ~~ has. The perlsyn page lists all of its behaviors.
19 Getting unique elements in a list my }; = keys %uniq; # makes a nice little subroutine sub uniq { my %u; return keys %u; }
20 Schwartzian Transform The Schwartzian Transform is a Perl sorting idiom devised by Randal Schwartz. Sometimes we want to sort a list of things by some arbitrary function of the elements. This can be troublesome if the function is very expensive say, computationally, or if involves I/O in some way. Randal s solution is to create a list of anonymous arrays, where each original list element is paired with the value that will be used for sorting. # first step of Schwartzian = map { [ $_, -s $_ ]
21 Schwartzian Transform = map { [ $_, -s $_ ] So now we have an array of 2-tuples (file name and file size, stored in anonymous arrays) that we want to sort using the second element of the = sort { $a->[1] <=> $b->[1] Now our data is sorted, but our data is stuck in that messy thing. Let s rescue = map { $_->[0] is our sorted list of files!
22 Schwartzian Transform: All Together Now We just stick the code samples together in reverse order, eliminating the temporary = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, -s $_ ] Once you get past the punctuation (I understand this is still a stumbling block for some of you), it s actually quite simple. We keep the sorting data with the data to be sorted so that we only compute it once. Then we remove that extra data when we no longer need it.
23 revisited The or operator (, or or for a very low precedence version of the same) is a good way to inject a default. sub new { my $class = shift; my %params bless { _foo => $params{foo} 10, _bar => $params{bar} bar, _baz => $params{baz} [ qw(a b c) ], }, $class; }
24 // is better here The // ( defined-or ) operator works like except that it uses a definedness test rather than truth. use v5.10; sub new { my $class = shift; my %params bless { _foo => $params{foo} // 10, _bar => $params{bar} // bar, _baz => $params{baz} // [ qw(a b c) ], }, $class; }
25 Another use for and // Sometimes we might use a hash as a cache for some computation, but we want to load it lazily (on demand). This idiom is common in this case: my $a = $foo{$val} //= foo($val); Assignment is right-associative, so the statement evaluates like this: my $a = ($foo{$val} //= foo($val)); If a value exists in the hash, we can just use it; otherwise we can use the function foo to compute the value, store it in the hash, and also put it in $a.
26 Subroutine/Function Review # What you already know # (named; not anonymous) sub named_func { #... } named_func(); # call
27 Anonymous subroutines/functions # Anonymous my $anon = sub { #... }; $anon->(); # call Notice the major differences: no function name after sub, assignment to a scalar, semicolon to end the assignment, and the ->() dereferencing-call syntax.
28 Stack homework revisited %ops = ( + => sub { (pop(@stack) + pop(@stack)); }, - =>... ); while(<>) { chomp; if ($ops{$_}) { $ops{$_}->(); } else #... }
29 Another type of reference $ perl print ref(sub{})."\n"; ^D CODE $ As you can see, ref will return the string CODE when presented with an anonymous function (other interchangable terminology: anonymous sub, coderef).
30 All subs are closures (even anonymous ones) In a code example last time we had code like this: { my $privatevar = 11; sub myfunc { my $a = $_[0] + $privatevar; #... $privatevar =... } sub myotherfunc { # can also see $privatevar } } The $privatevar variable goes out of scope, but since myfunc refers to it, it stays around like a static variable within that subroutine.
31 Generating counter functions sub makecounter { my $startvalue = shift; return sub { $startvalue++ }; } my $CounterA = makecounter(1); my $CounterB = makecounter(500); $CounterA->(); # returns 1 $CounterA->(); # returns 2 $CounterB->(); # returns 500 $CounterB->(); # returns 501 $CounterB->(); # returns 502 # etc.. We can provide each closure with its own private counter!
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 informationPERL 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 informationCS 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 informationPerl 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 information1. 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 informationCSCI-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 informationpairs unpairs pairkeys pairvalues pairfirst pairgrep pairmap
NAME SYNOPSIS List::Util - A selection of general-utility list subroutines use List::Util qw( reduce any all none notall first max maxstr min minstr product sum sum0 pairs unpairs pairkeys pairvalues pairfirst
More informationHash::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 informationOutline. 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 informationA control expression must evaluate to a value that can be interpreted as true or false.
Control Statements Control Expressions A control expression must evaluate to a value that can be interpreted as true or false. How a control statement behaves depends on the value of its control expression.
More informationPathologically 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 informationCOMS 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 informationHands-On Perl Scripting and CGI Programming
Hands-On Course Description This hands on Perl programming course provides a thorough introduction to the Perl programming language, teaching attendees how to develop and maintain portable scripts useful
More informationIT441. 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 informationCS 105 Perl: File I/O, slices, and array manipulation
CS 105 Perl: File I/O, slices, and array manipulation Nathan Clement January 27, 2013! Agenda Intermediate iteration last and next Intermediate I/O Special variables Array manipulation push, pop, shift,
More information$bool = $obj->mk_aliases( # create an alias to an existing alias_name => 'method'); # method name
NAME SYNOPSIS Object::Accessor - interface to create per object accessors ### using the object $obj = Object::Accessor->new; # create object $obj = Object::Accessor->new(@list); # create object with accessors
More informationIN CHAPTER 7, SUBROUTINES AND MODULES, you learned how to organize
8 Object-Oriented Programming IN CHAPTER 7, SUBROUTINES AND MODULES, you learned how to organize your code into subroutines, packages, and modules. In this chapter, you ll find out how to create objects
More informationTieing and Overloading Objects in Perl. Dave Cross Magnum Solutions
Tieing and Overloading Objects in Perl Dave Cross Magnum Solutions What We Will Cover Why tie or overload? What We Will Cover Why tie or overload? Tieing objects What We Will Cover Why tie or overload?
More information# use a BEGIN block so we print our plan before MyModule is loaded BEGIN { plan tests => 14, todo => [3,4] }
NAME SYNOPSIS Test - provides a simple framework for writing test scripts use strict; use Test; # use a BEGIN block so we print our plan before MyModule is loaded BEGIN { plan tests => 14, todo => [3,4]
More informationNAME 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 informationThese are notes for the third lecture; if statements and loops.
These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern
More informationClassnote 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 informationData::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 informationperl -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 informationLearning 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 informationPerl Tutorial. Diana Inkpen. School of Information Technology and Engineering University of Ottawa. CSI 5180, Fall 2004
Perl Tutorial Diana Inkpen School of Information Technology and Engineering University of Ottawa CSI 5180, Fall 2004 1 What is Perl Practical Extraction and Report Language. Created, implemented, maintained
More informationBeginning 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[Skip ahead to DESCRIPTION if you don't care about the whys and wherefores of this control structure]
NAME Switch - A switch statement for Perl SYNOPSIS use Switch; Perl version 5.12.1 documentation - Switch BACKGROUND case 1 { print "number 1" case "a" { print "string a" case [1..10,42] { print "number
More informationData::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 informationHigher Order Perl. Finlay Thompson. 14 March 2006
Finlay Thompson 14 March 2006 Talk Outline What is this all about? Some FP techniques and ideas Loops, recursion, iterators, chasing tails, loops Currying and anonymous subroutines Conclusions What is
More informationCS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output
CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables
More informationuse 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 informationIT441. Network Services Administration. Data Structures: Lists
IT441 Network Services Administration Data Structures: Lists Comment Blocks Perl normally treats lines beginning with a # as a comment. Get in the habit of including comments with your code. Put a comment
More informationIT441. 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 informationuse 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 informationNAME 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... and run the script as /path/to/script.pl. Of course, it'll need to be executable first, so chmod 755 script.pl (under Unix).
NAME DESCRIPTION What is Perl? perlintro -- a brief introduction and overview of Perl This document is intended to give you a quick overview of the Perl programming language, along with pointers to further
More informationDaMPL. Language Reference Manual. Henrique Grando
DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4
More informationPerl 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 informationPerl. Many of these conflict with design principles of languages for teaching.
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, C
More informationNAME 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 informationIntermediate 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 informationIntroduction to Perl Session 6. special variables subroutines Introduction to Perl
1.0.1.8.6 Introduction to Perl Session 6 special variables subroutines 6/17/2008 1.0.1.8.6 - Introduction to Perl - Special Variables and Subroutines 1 I/O Recap file handles are created using open(f,$file);
More informationCSCI-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 informationCSCI 4152/6509 Natural Language Processing. Perl Tutorial CSCI 4152/6509. CSCI 4152/6509, Perl Tutorial 1
CSCI 4152/6509 Natural Language Processing Perl Tutorial CSCI 4152/6509 Vlado Kešelj CSCI 4152/6509, Perl Tutorial 1 created in 1987 by Larry Wall About Perl interpreted language, with just-in-time semi-compilation
More informationThis document describes version 2.10 of Switch, released Dec 29, 2003.
NAME Switch - A switch statement for Perl VERSION This document describes version 2.10 of Switch, released Dec 29, 2003. SYNOPSIS use Switch; BACKGROUND case 1 { print "number 1" case "a" { print "string
More informationPerl. 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 informationBeginning Perl. Mark Senn. September 11, 2007
GoBack Beginning Perl Mark Senn September 11, 2007 Overview Perl is a popular programming language used to write systen software, text processing tools, World Wide Web CGI programs, etc. It was written
More informationObject-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 informationArguments of the use overload directive are (key, value) pairs. For the full set of legal keys, see Overloadable Operations below.
NAME overload - Package for overloading Perl operations SYNOPSIS package SomeThing; use overload '+' => \&myadd, '-' => \&mysub; # etc... DESCRIPTION Fundamentals Declaration package main; $a = SomeThing->new(
More informationprint 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 informationPerl. 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 informationCOMS 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 informationIndicate the answer choice that best completes the statement or answers the question. Enter the appropriate word(s) to complete the statement.
1. C#, C++, C, and Java use the symbol as the logical OR operator. a. $ b. % c. ^ d. 2. errors are relatively easy to locate and correct because the compiler or interpreter you use highlights every error.
More informationThe 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 informationCOMS 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 informationIntroduce C# as Object Oriented programming language. Explain, tokens,
Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation
More informationProgramming for Engineers Iteration
Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers
More informationThe 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 informationthreads::shared - Perl extension for sharing data structures between threads
NAME VERSION SYNOPSIS threads::shared - Perl extension for sharing data structures between threads This document describes threads::shared version 1.56 use threads; use threads::shared; my $var :shared;
More information@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 informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationClosures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming
Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Summary 1. Predictive Parsing 2. Large Step Operational Semantics (Natural) 3. Small Step Operational Semantics
More information$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 informationFortunately, you only need to know 10% of what's in the main page to get 90% of the benefit. This page will show you that 10%.
NAME DESCRIPTION perlreftut - Mark's very short tutorial about references One of the most important new features in Perl 5 was the capability to manage complicated data structures like multidimensional
More informationClosures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming
Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming t ::= x x. t t t Call-by-value big-step Operational Semantics terms variable v ::= values abstraction x.
More informationCS112 Lecture: Working with Numbers
CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More information(Refer Slide Time: 01:12)
Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #22 PERL Part II We continue with our discussion on the Perl
More informationSEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7
SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7 Hi everyone once again welcome to this lecture we are actually the course is Linux programming and scripting we have been talking about the Perl, Perl
More informationObject 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 informationperl -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 informationNow applying :unique to lexical variables and to subroutines will result in a compilation error.
NAME DESCRIPTION perl591delta - what is new for perl v5.9.1 This document describes differences between the 5.9.0 and the 5.9.1 development releases. See perl590delta for the differences between 5.8.0
More informationCS 360 Programming Languages Interpreters
CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like
More informationCSCI-GA Scripting Languages
CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationModularity and Reusability I. Functions and code reuse
Modularity and Reusability I Functions and code reuse Copyright 2006 2009 Stewart Weiss On being efficient When you realize that a piece of Perl code that you wrote may be useful in future programs, you
More informationScripting 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 informationIntroduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.
Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations
More informationCS1 Lecture 3 Jan. 22, 2018
CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow
More informationIntermediate Perl Session Intermediate Perl. map transforming data. sort ranking data. grep extracting data
1.1.2.8.3 Intermediate Perl Session 3 map transforming data sort ranking data grep extracting data use the man pages perldoc f sort perldoc f grep, etc 8/5/2008 1.1.2.8.3 - Intermediate Perl - sort/grep/map
More informationCP150 - 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 information5th State of the Onion. Larry Wall
5th State of the Onion Larry Wall Talk 1 An Overview of Perl Perl 5 Perl 6 Talk 2 Bits and Pieces 33 lightning talks in half an hour See Apocalypse 2 Expected apocalyptic error rate: 5% Talk 3 Unary and
More informationegrapher Language Reference Manual
egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction
More informationObject 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 informationControl Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003
Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an
More informationCSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)
CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent
More informationJavaScript: Sort of a Big Deal,
: Sort of a Big Deal, But Sort of Quirky... March 20, 2017 Lisp in C s Clothing (Crockford, 2001) Dynamically Typed: no static type annotations or type checks. C-Like Syntax: curly-braces, for, semicolons,
More informationmy $reply = $term->get_reply( prompt => 'What is your favourite colour?', choices => [qw blue red green ], default => blue, );
NAME SYNOPSIS Term::UI - Term::ReadLine UI made easy use Term::UI; use Term::ReadLine; my $term = Term::ReadLine->new('brand'); my prompt => 'What is your favourite colour?', choices => [qw blue red green
More informationFunctional Programming. Pure Functional Programming
Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).
More informationA Field Guide To The Perl Command Line. Andy Lester
A Field Guide To The Perl Command Line Andy Lester andy@petdance.com http://petdance.com/perl/ Where we're going Command-line == super lazy The magic filehandle The -e switch -p, -n: Implicit looping -a,
More informationUsing References to Create Complex Structures. The array and hash composers
Using References to Create Complex Structures The array and hash composers Copyright 2006 2009 Stewart Weiss Anonymous array composer You can create a hard reference to an anonymous array using square
More informationCSE 341, Autumn 2015, Ruby Introduction Summary
CSE 341, Autumn 2015, Ruby Introduction Summary Disclaimer: This lecture summary is not necessarily a complete substitute for atting class, reading the associated code, etc. It is designed to be a useful
More informationThe e switch allows Perl to execute Perl statements at the command line instead of from a script.
CH02.DOC Page 5 Friday, January 26, 2001 2:35 PM 2 Perl Scripts 2.1 Perl at the Command Line Although most of your work with Perl will be done in scripts, Perl can also be executed at the command line
More informationParsing Scheme (+ (* 2 3) 1) * 1
Parsing Scheme + (+ (* 2 3) 1) * 1 2 3 Compiling Scheme frame + frame halt * 1 3 2 3 2 refer 1 apply * refer apply + Compiling Scheme make-return START make-test make-close make-assign make- pair? yes
More information9.2 Linux Essentials Exam Objectives
9.2 Linux Essentials Exam Objectives This chapter will cover the topics for the following Linux Essentials exam objectives: Topic 3: The Power of the Command Line (weight: 10) 3.3: Turning Commands into
More informationCS Summer 2013
CS 1110 - Summer 2013 intro to programming -- how to think like a robot :) we use the Python* language (www.python.org) programming environments (many choices): Eclipse (free from www.eclipse.org), or
More informationpackage 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 informationCSCI-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