Perl (programming language)

from Wikipedia, the free encyclopedia
Pearl
Paradigms : procedural , modular , partly object-oriented
Publishing year: 1987
Designer: Larry Wall
Developer: Larry Wall , Perl Porter
Current  version : 5.32.0   (June 20, 2020)
Typing : weak , dynamic , implicit
Influenced by: awk , BASIC-PLUS, C / C ++ , Smalltalk , Lisp , Pascal , Python , sed , Unix-Shell
Affected: PHP , Ruby , Python , JavaScript , Windows PowerShell
Operating system : platform independent
License : GPL and Artistic License
www.perl.org

Perl [ pɝːl ] is a free , platform-independent and interpreted programming language ( scripting language ) that supports several programming paradigms .

The linguist Larry Wall designed it in 1987 as a synthesis of C , awk , the Unix commands and other influences. Originally intended as a tool for processing and manipulating text files, particularly for system and network administration (e.g. evaluation of log files ), Perl has also found widespread use in the development of web applications and in bioinformatics . Perl is also traditionally represented in the financial world, especially in the processing of data streams from various news sources. The main goals are fast problem solving and the greatest possible freedom for programmers. The processing of texts with the help of regular expressions and a large scope of design are strengths of the language.

history

Emergence

Larry Wall designed Perl.

Larry Wall was employed as an administrator and programmer at Unisys , where he had been involved since March 1987 in developing a secure network for the NSA under the name blacker . He received several orders to create tools for monitoring and remote maintenance of the emerging software . One of the main tasks was to generate clear reports from scattered log files . Since the existing languages ​​and tools seemed too cumbersome for him, he gradually developed his own language with the help of his teammate at the time Daniel Faigin and his brother-in-law Mark Biggar to solve his tasks.

He also drew on his knowledge and experience as a linguist and designed Perl close to human language habits. This is expressed in minimum requirements for beginners, a strong combinability of language elements and a rich vocabulary that also allows commands whose meanings overlap. Wall sees a practitioner's need for freedom and intuitive expression in this.

In line with this practical approach, Perl borrowed its vocabulary and logical structures from the languages ​​and tools used under Unix in the 1980s , which made learning easier, but also reversed the Unix philosophy . Unix and its system commands were compiled and mostly in C written. These commands were logical units and should master exactly one task: "Do one thing and do it well" ("Do one thing and do it well"). Interpreted shell scripts quickly and easily combined the commands, which could pass their results on to one another through pipes . Perl violates this philosophy by making these commands part of the programming language, combining C and Shell and bypassing the existing commands and tools.

This became necessary because shell scripts were unsuitable for complex tasks. Their process is very simple, they can only temporarily store data to a limited extent and the pipes are bottlenecks in data exchange . On the other hand, they allow a much more compact programming style, since the use of a UNIX tool can replace many lines of C source code .

In order to take advantage of both types of programming, Wall created a combination of C and tools like sed , awk , grep and sort . He added properties of the Bourne Shell , to a lesser extent elements from Pascal and BASIC , as well as his own ideas. This fusion enabled short, powerful programs that could be written quickly and tested at any time without having to compile them, which also accelerated development. Later other languages ​​like Lisp , Smalltalk , Python or Ruby were “imported”.

Surname

The name Perl refers to a quote from the Gospel of Matthew ( Mt 13.46  EU ), in which Jesus describes the kingdom of heaven with the image of a trader who wants to sell all his possessions in order to buy a precious pearl . Before the release, the name was changed from "Pearl" to "Perl", as there was already a programming language called PEARL . The Backronymes Practical Extraction and Report Language and Pathologically Eclectic Rubbish Lister are also widely used and accepted by Larry Wall . The spelling “Perl” designates the language, “Perl” on the other hand the program that interprets this language. Furthermore, the Perl community attaches great importance to the fact that the spelling “PERL” is not used, since it is not an acronym .

Pearl 1 to 4

Larry Wall was an employee of the Jet Propulsion Laboratory (JPL) at the time.

On December 18, 1987, Larry Wall published his program on Usenet as Perl 1.0, which at that time was a more powerful shell that could handle texts and files, control other programs, and output legible reports. Version 2.0 was released on June 5th the following year with a completely new and expanded Regex engine and a few other improvements. Perl 3 followed on October 18, 1989, which could handle binary data and also enabled network programming. The GPL was chosen as the new license .

Almost unchanged, it was available as Perl 4 from March 21, 1991, but now either under the GPL or the Artistic License developed by Larry Wall . The real reason for the new version, however, was the camel book that appeared at the same time and was published as a reference for the current version marked as version 4. Until then, the UNIX man pages available since Perl 1 were the only documentation available. These offer a well-founded and extensive treatise on every topic, but not an easy introduction for Perl beginners.

The book written by Randal L. Schwartz , Larry Wall and Tom Christiansen was supposed to fill this gap . It was published by O'Reilly Verlag , which with this and other titles became known as a renowned specialist publisher for programmers. O'Reilly's Perl books became the authoritative publications, which was only put into perspective in the new millennium. The publisher also operated the most popular online magazine for Perl programming at perl.com and organized the largest Perl conference, TPC (The Perl Conference - today OSCON ). O'Reilly benefited from Perl's growing popularity, and in return Tim O'Reilly paid his friend Larry Wall a fixed salary in the years that followed, so that he could devote himself to the further development of the language without further obligations or guidelines.

In 1993, when Perl reached version 4.036, Larry Wall stopped developing it and developed Perl 5 from scratch.

Pearl 5

CPAN : One of the largest
free software archives

Perl 5.0 was released on October 18, 1994 and was the biggest advance in the language to date. With Plain Old Documentation you could now insert formatted documentation into the source text. From now on, the language could also be expanded with separate modules, which led to the creation of the CPAN in the following year . This large archive of freely available modules eventually became an important reason for using Perl itself. Another important innovation was the introduction of references , which for the first time allowed a simple creation of composite data structures .

With version 5 it was also possible to program object-oriented in Perl. Larry Wall chose an unusual way and derived the syntax used for it almost exclusively from existing language elements (packages, package functions and package variables as well as the new references). Only the function bless()for creating an object and the arrow operator ( ->) for calling methods were added (the arrow operator is actually the dereferencing operator that dereferences a certain method from an object that consists of a reference to the class). XS was also created, an interface description language that enables Perl programs to be extended with other languages ​​or to address any software or hardware with Perl programs .

Since the release of Perl 5, Larry Wall has hardly participated in the development of the language. This was done voluntarily by Perl-enthusiastic programmers, the so-called Perl 5 Porters, who communicate via the p5p mailing list founded in May 1994, but also increasingly decide on bug fixes and new language functions via their own bug and request tracker (RT). A so-called pumpking takes over the management for each version . The term Perl Porter comes from the original task of the p5p list of coordinating the porting of Perl to other operating systems.

In the years after version 5.0, not only was Perl ported to Macintosh and Windows, but the numbering of the versions also shifted. Since the syntax did not change significantly, the 5 was left and the first decimal place increased for larger milestones, but additional numbers were used to count the intermediate steps. Since Perl was only able to handle version numbers that contained several commas from 5.6 onwards, they were B. Perl 5.001 or Perl 5.001012 written. From 5.6 on, the version scheme used by Linux at that time was also adopted, in which even numbers indicate error-free user versions and odd numbers indicate developer versions in which new functions are incorporated. Series of user versions (e.g. 5.8.x) are kept binary compatible with each other, which means that a binary module compiled for Perl 5.8.7 also works with 5.8.8, but not necessarily with 5.10 or 5.6.1.

Perl 5.6

This version brought some new experimental capabilities on March 22, 2000 that only matured later, such as Unicode and UTF-8, threads, and cloning. 64-bit processors could now also be used. Linguistically, this series headed by Gurusamy Sarathy mainly added lexically global variables (with our) and a vector notation that allows the comparison of multi-digit version numbers, as well as the special variables @-and @+.

Perl 5.8

The 5.8.x series, which Nicholas Clark took care of on July 18, 2002, mainly resolved the problems with Unicode and the threads, but also the input / output (IO), signals and the numerical accuracy were decisively improved.

From Perl 5.10

In addition to reduced memory consumption and a renewed and now interchangeable regex engine, this version brought on 18 December 2007 under the leadership of Rafaël Garcia-Suarez, especially innovations that come from the design of Perl 6 and their use, either individually or collectively use feature ':5.10';be registered must or shorter use v5.10;. From this version on, this applies to all functions that could break compatibility. These include say, givenand when(analogous to the switchstatement in C ), the smartmatch operator ( ~~), the defined or operator ( //) and statevariables, which simplify the creation of closures . Other noteworthy innovations include the relocatable installation path, stackable file test operators, definable lexical pragmas, optional C3 serialization of object inheritance and field hashes (for "inside out" objects). The regex engine now works iteratively instead of recursively, which enables recursive expressions. Complex search queries can now be formulated in a more understandable and less error-prone manner using named captures . The special variables$# and $*and the interpreter interfaces perlcc and JPL have been removed.

The following year the source was switched from Perforce to Git , which made it much easier to develop and release new versions.

Perl 5.12

This April 12, 2010 version, directed by Jesse Vincent, contains far fewer major and visible changes than 5.10. use v5.12;implies use strict;and use feature 'unicode_strings';, which makes all commands treat strings as unicode. Among the technical improvements, the updated Unicode (5.2), DTrace support and security of dates beyond 2038 are particularly noteworthy, suidperl has been removed. The ellipse operator ( yada-yada ) and the regex escape sequence \ N have been adopted from Perl 6 , module versions can now be managed by package and use . Another new feature is the ability to define your own keywords using Perl routines. However, this is marked as experimental and is subject to change. For better planning and collaboration with distributions, a developer version will appear from December 5, 2000 on the 20th of every month, a small user version every 3 months and a large one every year.

Perl 5.14

As of May 14, 2011, new modifiers and control characters make it easier to use Unicode , which has been updated to 6.0. Built-ins for lists and hashes are automatically dereferenced ( autoderef ) and large parts of the documentation have been revised or rewritten. Support for IPv6 has also been improved and the connection of multithread libraries has been made easier.

Perl 5.16

The version released on May 20, 2012 contains numerous syntactic smoothing, partly updated documentation and the change to Unicode 6.1. Jesse Vincent and from November 2011 Ricardo Signes were in charge. Thanks to a newly opened donation pot from the Perl Foundation , two long-time developers have been obliged to complete thankless tasks and to simplify the build process . The only fundamentally new functionality is the token that can be activated with use feature 'current_sub';or , a reference to the current routine . use v5.16; __SUB__

Perl 5.18

The functionalities lexical subroutines ( lexical_subs ) and character classes generated with set functions within regular expressions, which were published on May 18, 2013, are both experimental. Such functions, which also include lexical context variables ( lexical_topic ) and the Smartmatch operator, now generate warnings starting with no warnings 'experimental :: function-name'; or no warnings 'experimental'; can be switched off. The hashes were consistently randomized in order to better protect programs against DoS attacks .

Perl 5.20

Also under the leadership of Ricardo Signes, the experimental functionalities of the subroutine signatures ( signatures ) and ( postderef ) an alternative postfix syntax for dereferencing came on May 27, 2014 . The autoderef recorded at 5.14 has been downgraded as experimental. Unicode 6.3 is supported and with drand48 Perl now has its own, platform-independent, good random number generator. String and array sizes are now 64-bit values.

Perl 5.22

On June 1, 2015, the double diamond operator (<< >>), bitwise string operators (&. |. ^. ~.), A 'strict' mode for regular expressions use re 'strict';( re_strict ), Unicode 7.0, aliasing of references ( refaliasing ) and constant routines ( const_attr ), which always return the constant value determined with the first compilation. All functionalities mentioned (name in brackets) are experimental for the time being.

Perl 5.24

brought accelerations for blocks and numerical operations as well as Unicode 8.0 on May 9, 2016 . The postderef and postderef_qq features were accepted - autoderef and lexical_topic removed.

Perl 5.26

Under the direction of SawyerX, the regex option xx, indentable Here documents and Unicode 9.0 were introduced on May 30, 2017 . The lexical_subs feature has been adopted and '.'(the current directory) has been removed from @INC(the list of search paths for modules) by default for security reasons .

Perl 5.28

Released on June 22, 2018. In addition to Unicode 10.0, Perl received long and short versions of alpha assertions. These are aliases for special regex groups with meaningful names: for example instead of (? = ...), now also (* positive_lookahead: ...) or (* pla: ...). (* script_run:…) or (* sr:…) was introduced in order to recognize uniformly coded text, which helps avoid attacks through manipulated input. Three critical security holes have been closed, multiple dereferences and string merges have been accelerated, and the operators (&. |. ^. ~.) Are no longer experimental. In addition, it was decided to keep a record in the document perldeprecation about when which function (with 2 versions of warning time) is removed.

Perl 5.30

Updated on May 22, 2019 to Unicode 12.1, introduced the Unicode Wildcard Properties and allowed a lookbehind to be limited in length. Removes were $ [ , $ * , $ # and File :: Glob :: glob , and variable declarations in trailing, conditional expressions.

Perl 5.32

Introduced concatenated comparison operators ($ d <$ e <= $ f), the isa operator (checks class membership) and Unicode 13 on June 20, 2020. \ p {name = ...} allows to interpolate expressions to Unicode names within a regex.

Current versions

Even if the latest user version is 5.32.0, the version series 5.30.x is currently still being maintained (the current version is 5.30.3). The versions 5.28.3, 5.26.3, 5.24.4, 5.22.4, 5.20.3, 5.18.2, 5.16.3, 5.14.4, 5.12.5, 5.10.1 and 5.8.9 are the end of their series, Security-relevant improvements will be submitted up to 3 years after the release of a version. With core modules, attention is usually paid to compatibility up to 5.6, with important CPAN modules usually 5.8.3. Current changes are being made in Developer Branch 5.31, which is not intended for general use. The next version of Perl will be Perl 7 and not Perl 6. Perl 6, which was renamed Raku in 2020, is a sister language whose interpreter and surrounding infrastructure have been completely redesigned.

Raku (pearl 6)

See raku

features

Principles

Perl was developed for practical use and therefore focuses on quick and easy programmability, completeness and adaptability. This philosophy is expressed in the following slogans or phrases, most of which are from Larry Wall.

Multiple ways

The best-known and most fundamental Perl motto is "There is more than one way to do it" (German: "There is more than one way to do something"), which usually translates to TIMTOWTDI (rarely TMTOWTDI) or (with English contraction ) "Tim To [a] dy" is shortened. In contrast to languages ​​like Python, Perl makes fewer specifications and intentionally offers several formulation and solution options for every problem ( syntactic sugar ). For example, logical operators can be written as ||and &&(as in C) or (with nuances of meaning) as orand and(as in Pascal); but also numerous commands with an overlapping range of functions such as mapand forallow different formulations for the same situation. Some commands like the diamond operator ( <>) offer abbreviated notations for already existing functionality (here would be <STDIN>equivalent, with slight differences, but which would have to be written much longer). This diversity is also visible in the CPAN , where often several modules fulfill a very similar purpose or one that could also (albeit more cumbersome) be implemented ad hoc (example Getopt::Long).

Another catchphrase, which can also be seen as an extension of TIMTOWTDI, describes Perl as the first postmodern programming language. This means that Perl combines different paradigms and the user is free to combine structured, object-oriented, functional and imperative language features.

Simple and possible

The other important motto is Perl makes easy jobs easy and hard jobs possible , which means in German "Perl keeps simple tasks simple and makes (the solution) difficult (s) tasks possible". First of all, this includes the goal of simplifying common tasks as far as possible with short “ready-made solutions”. For example, checks the existence of a file. For Perl, however, leaving simple tasks simple also means not requiring any preparatory programming instructions, such as registering variables or writing a class. Second, Perl tries to be complete and to provide at least the basics of every problem that make a solution possible. The third goal, not to let the first two goals collide, is becoming more and more important with the growing language scope of Perl 6, where, based on the Huffman code, the notations of the most frequently used commands are kept as short as possible, without involving the logic to break the spelling of similar commands. -e dateiname

Context sensitive

In Perl there are commands that have different meanings depending on the context in which they are used. Data structures like the array are context-sensitive in this way. If it is assigned to another array, its content is transferred; if the recipient is a single value ( scalar ), it receives the length of the array.

technical features

The Perl interpreter itself is a program written in C that can be compiled on almost any operating system. However, precompiled versions on seldom used systems such as BeOS or OS / 2 are not always up to date. The source code is around 50 MB and also contains Perl scripts that take over the function of Makefiles and the test suite. The compiled program is typically around 850 KB in size, but this can vary depending on the operating system, compiler and libraries used.

Perl scripts are stored in text files with any line separator. When a script is started, it is read in by the Perl interpreter, converted into a parse tree , this into bytecode , which is then executed. The parser integrated in the interpreter is an adapted version of GNU Bison .

Strictly speaking, Perl is not an interpreted language because a Perl program is compiled before it is executed . This leads to the fact that - in contrast to purely interpreted languages ​​- a program with syntax errors does not start.

distribution

In the beginning, Perl was a UNIX tool that was specially designed for processing text files, controlling other programs and outputting reports. To this day, it is used on all common operating systems, and not just by system administrators. Perl also got the reputation of a glue language , because incompatible software can be linked with the help of relatively quickly written Perl scripts. To this day, Perl is part of the basic configuration on all POSIX- compatible and Unix-like systems.

With the spread of the World Wide Web , Perl was increasingly used to connect web servers , databases and other programs and data and to output the results in the form of HTML pages. The Perl interpreter is addressed by the web server via CGI or FastCGI or is embedded directly in the server. ( mod perl in Apache , ActiveState PerlEx in Microsoft IIS ). Even though PHP has become more popular for this server-side script programming , Perl is still used by many large and small sites and Internet services such as Amazon.com , IMDb .com , slashdot .org, Movable Type , LiveJournal and XING . Since Perl scripts are often barely recognizable in many important places, Perl was also jokingly referred to as the tape that holds the Internet together. Frameworks such as Mason , Catalyst , Jifty, Mojolicious and Dancer were also created in Perl , which allow complex and easily modifiable websites to be developed very quickly. Wiki software is also often written in Perl. B. Social text, which is based on Mason, Kwiki, TWiki , Foswiki , ProWiki or UseMod . Popular ticket systems with web interfaces such as Bugzilla or RT are also written in Perl.

However, web applications are still just one of Perl's many uses. Important Perl programs in the e-mail area are SpamAssassin ( spam filter), PopFile and open webmail . For example, Perl is used for system administration in debconf , a part of the package management of the Debian operating system .

Other main fields of application are data munging and bioinformatics, where Perl has been the most frequently used language since 1995 and is still important. The reasons for this are again the ability to process information in text form and the flexibility and openness of the language, which allow the international research community to work together despite the different standards of the institutes. BioPerl is the most important collection of freely available tools here, focusing primarily on the area of genome sequence analysis. Perl played an important role in the Human Genome Project .

Even desktop applications and games like Frozen Bubble can be written in Perl. Today's computers are fast enough to run these programs fluently.

Areas in which script languages such as Perl cannot be used sensibly are, on the one hand, applications with high requirements in terms of hardware proximity or speed, such as drivers or codecs . On the other hand, they should not be used in highly safety-critical areas (e.g. aircraft control), since due to the lax syntax check (e.g. missing / very weak type system ) many errors do not occur until runtime and verification is generally not possible.

Perl ports existed for over 100 operating systems.

Perl and other programming languages

For tasks that are difficult or slow to solve with Perl, Perl offers the Inline module, an interface through which program parts in other languages ​​can be integrated into a Perl program. Supported languages ​​include a. C , C ++ , Assembler , Java , Python , Ruby , Fortran and Octave .

Areas of application are e.g. B .:

  • computationally intensive formulas ( C , assembler ),
  • Solving complex problems with existing systems ( Octave , Fortran - Libraries ) and
  • merging of applications in different languages ​​("glue function" of Perl).

Using Inline is relatively easy and well documented. In the case of compiled program parts, Inline keeps a record of the version status using the MD5 identifier, which avoids multiple compilation of the same code.

With inline, the transfer of the parameters and the return of the results require some effort. With short calculations, this effort outweighs the gain in speed. For example, if the Mandelbrot set is calculated by calculating the formula via inline as a C function , but leaving the iteration in Perl, program execution slows down compared to a pure Perl implementation. On the other hand, if the iteration loop is also outsourced in C , the performance increases significantly.

Logos

Tim O'Reilly was one of Perl's key supporters for many years. His publisher holds the rights to perhaps the most important Perl logo: the camel.

A dromedary serves as Perl's mascot . For the first time it adorned the cover of the reference work Programming Perl, also known as the camel book . His publisher ( Tim O'Reilly ) jokingly said in an interview as a reason: Perl is ugly and can do without water for long stretches. The dromedary can be seen on the Programming Republic of Perl emblem, which is often viewed as the official Perl logo and which allows O'Reilly to use it for non-commercial purposes. Other logos used in connection with Perl, besides pearls, are the sliced onion (identification mark of the Perl Foundation ) and the Komodo dragon , which adorns the widespread Perl distribution ActivePerl from ActiveState.

syntax

Free format

Perl allows conditionally format-free source code. This means that indentations and additional spaces are syntactically irrelevant and line breaks can be inserted as desired. To do this, commands in a block must be separated by a semicolon. Some language elements, such as formats, heredocs, and common regular expressions, are not freeform.

variables

A characteristic of Perl is that variables are identified by a prefix (also called a sigil ), which indicates their data type. Here are some examples:

  • $ for scalars: $scalar
  • @ for arrays: @array
  • % for hashes (associative arrays): %hash
  • & for functions (often optional): &function
  • * for typeglobs: *all

File handles , directory handles and formats have no prefix, but are also independent data types. Each data type has its own namespace in Perl .

Basic data types in Perl are scalar variables , arrays and hashes ( associative arrays ).

  • Scalars are typeless variables for single values; they can contain strings , numbers (integer / floating point) or references to other data or functions. Strings and numbers are automatically and transparently converted into one another when required, a great feature of Perl.
  • Arrays combine several scalars under one variable name. Array entries have an index. The count starts at 0, unless otherwise specified.
  • Hashes also summarize scalars, but here individual values ​​are not clearly identified and addressed using numerical indices, but with the help of associated keys . Any character string can be used as the key, or anything that can be converted into a character string.

Hashes and arrays can be assigned to one another, whereby hashes are viewed as lists of key / value pairs. Data of different types can be combined as required to form new data structures using references; for example, hashes are conceivable that contain individual scalars in addition to (references to) arrays.

Package variables are created automatically the first time they are used. Validity-restricted variables are used far more frequently in modern parlance. These must be mydeclared using. ourmakes a variable available throughout the program. releases the specified variable again. undef variable

Control structures

The basic control structures hardly differ from those in C, Java and JavaScript .

Conditional execution

ifworks as known from C; unless (<Bedingung>), a special feature of Perl, is a notation for if (!(<Bedingung>)). A case or switch instruction ( given when) is only available from Perl 5.10, before this structure had to be if … elsif … elsereproduced. However, giventhe context variable ( $_) sets how forand whenapplies smartmatch ( ~~) to what makes this construct much more versatile than traditional case commands. The optional defaulthere corresponds to one else. The optimized logical operators also allow conditional execution. With or(or ||) the second expression is executed if the result of the first is not a true value, and(or &&) works analogously.

  if   (<Bedingung>) {<Anweisungen>}
 [elsif (<Bedingung>) {<Anweisungen>}]
 [else         {<Anweisungen>}]

  unless (<Bedingung>) {<Anweisungen>}
 [else         {<Anweisungen>}]

  given (<variable>) {
      [when (<Wert>) {<Anweisungen>}]
      [default    {<Anweisungen>}]
  }

 <Bedingung> ? <Anweisung1> : <Anweisung2>;

 <Ausdruck1> || <Ausdruck2>;
 <Ausdruck1> && <Ausdruck2>;

grind

As in C and iterate (in the variant based on C) as long as the condition is true until it is true, and iterates over a list. In Perl 5, and are interchangeable. whileforuntilforeachforforeach

 [label:] while (<Bedingung>)
              {<Anweisungen>} [continue {<Anweisungen>}]

 [label:] until (<Bedingung>)
              {<Anweisungen>} [continue {<Anweisungen>}]

 [label:] for ([<Startanweisung>]; [<Bedingung>]; [<Updateanweisung>])
              {<Anweisungen>} [continue {<Anweisungen>}]

 [label:] for[each] [[my] $element] (<Liste>)
              {<Anweisungen>} [continue {<Anweisungen>}]

lastimmediately exits the loop, redorepeats the current iteration, and nextjumps to the continueblock before continuing with the next iteration . These commands can be followed by a label identifier which, in the case of nested structures, determines which loop the command refers to.

 do {<Anweisungen>} while <Bedingung>; # Spezialfall: in dieser Form
 do {<Anweisungen>} until <Bedingung>; # mindestens eine Ausführung

Follow-up control structures

The control structures listed above relate to a block with several instructions. In the case of individual instructions, you can also choose the abbreviated, trailing spelling, which also makes it easier for the (English-speaking) readers to understand by using natural-language wording.

 <Anweisung> if   <Bedingung>;
 <Anweisung> unless <Bedingung>;

 <Anweisung> for   <Liste>;
 <Anweisung> while  <Bedingung>;
 <Anweisung> until  <Bedingung>;

Regular expressions

Since its inception, regular expressions (regex) have been a special feature of Perl, as until then only specialized languages ​​like Snobol and awk had similar capabilities . Due to its widespread use, Perl set an unofficial standard, which was taken up by the PCRE library , which is independent from Perl and also partially different , and which is now used by several important languages ​​and projects.

Starting with version 5.0, Perl has extended its regex capabilities to many functions, such as B. Backward References, expanded. Regular expressions in Perl can also be used much more directly than e.g. B. in Java - with the =~operator, as they are the core part of the language and not a switchable library. The actual regular expression is noted with forward slashes as delimiters. Because slashes can often appear within regular expressions, many other characters can also be used for delimitation. This improves readability, because you can choose characters that stand out from the content of the regular expression.

Perl knows two regular expression commands, the behavior of which can be changed with many trailing options.

  • The mcommand stands for match , which means match. This mcan be omitted when using the standard regular expression delimiters, namely slashes. The following expression searches the content of the variable $varand returns an array of character strings which the search expression matches. With the goption activated , the search in the list context returns all finds, deactivates all recognized subexpressions. In the scalar context, the expression returns a positive value if the search expression was found, with the -option cthe number of finds. iignores upper and lower case, ointerpolates variables only once, treats mthe string as multi-line and ssingle-line. The xoption makes it possible to distribute the search expression over several lines for better readability and to provide it with comments.
 $var =~ [m]/<Suchausdruck>/[g[c]][i][m][o][s][x];
  • The scommand stands for substitute , which means to replace. It replaces the part of the given text on which the search term fits with the replacement term.
 $var =~ s/<Suchausdruck>/<Ersatzausdruck>/[e][g][i][m][o][s][x];

After successfully using a regular expression, the following special variables are available:

  • $& - the recognized string
  • $` - String before the recognized string
  • $' - String after the recognized string
  • $1.. $n - Results of the parenthesized subexpressions
  • $+ - the last recognized subexpression
  • @- - Start offsets of hits and sub-hits
  • @+ - associated end offsets

The operator often described in the same breath as m//and has only the spelling in common with them. It is based on the UNIX command , which is used to replace individual characters. Synonym can take also be written. s///tr///trtry

 $var =~ tr/<Suchzeichen>/<Ersatzzeichen>/[c][d][s];

In addition to these two, the command splitthat divides a character string using a separator, which can also be a regular expression, can also be mentioned.

Quoting and Interpolation

Quoting operators:

  • q - quote uninterpreted string (alias to '')
  • qq - quote interpreted string (alias to "")
  • qw - quote words, a list of strings separated by whitespace
  • qr - quote regex
  • qx - quote external application to be executed

Alternative quoting and variable interpolation lead to particularly easy-to-read code. An example to clarify:

  • String concatenation and quoting characters in the text make the code difficult to read.
  $text = 'He\'s my friend ' . $name . ' from ' . $town . '.'
        . ' ' . $name . ' has worked in company "' . $company . '" for ' . $years . ' years.';
  • Interpolation of variables in the string now make the result recognizable. Escapes \ disturb the flow of text.
 $text = "He's my friend $name from $town. $name has worked in company \"$company\" for $years years.";
  • Exchanging the quoting character makes escapes superfluous. The code is now optimal. qqinitiates the quoting of variables in the string. Any character after that is the quoting character for this string.
 $text = qq{He's my friend $name from $town. $name has worked in company "$company" for $years years.};

criticism

The most common criticism of Perl is its poor readability. Any non-trivial program is read far more often than it is written. In fact, Perl offers an above-average amount of freedom that can lead to illegible code (see Disciplines ) . On the other hand, the same freedom also makes it possible to program close to the logical structure of the problem or human understanding. The freedom to pursue personal preferences, valued by Perl programmers, must be restricted by self-imposed rules in projects that are developed by several programmers or over long periods of time in order to avoid problems later. This requires additional communication effort or the use of software such as Perl :: Critic .

Some parts of the syntax, such as object orientation and signatures , are simple and very powerful, but are often perceived as outdated compared to comparable languages ​​such as Python or Ruby and require additional typing and thinking in standardized approaches, especially from Perl beginners. These problems should be fixed in Perl 6 or can be avoided with additional modules available for Perl 5. With Moose there is a very modern and extensive object system that is based heavily on that of Perl 6. Moose is now considered the de facto standard for object-oriented programming with Perl. Signatures were introduced at 5.20 but are still classified as experimental.

Perl was also accused of violating the UNIX philosophy. For more information, see the Origin section .

On the occasion of Perl's 30th birthday, iX said in December 2017 that the language had fallen behind the success of Java , PHP , Ruby and Python and could no longer catch up. Perl's reputation was "ruined". Unfortunately, it is currently considered a “'Write once, never read again' language, fed by years of 'Obfuscated is cool' culture and by propagating the worst aspects of Perl.” Perl is “now a niche language, pursued by lovers in theirs Leisure."

Strong criticism is also raised against Perl 6, which has set goals that are too ambitious and after many years still does not bring any visible results, instead paralyzing the future of Perl (5). From the beginning, Perl 6 was proclaimed a long-term project based exclusively on volunteer work that could not always be planned and with little financial support. Its concrete goals only emerged in the course of development, and there were clear problems with communication and external presentation. However, since Perl 5.10, significant innovations have come from Perl 6.

Perl culture and fun

Community

Perl Foundation logo

As with other free software projects, there are special social bonds between many developers and users of the language, and a culture of their own has developed from them. The Perl culture is characterized by openness, hospitality and helpfulness, but also by individualism , playfulness and humor. In the beginning Larry Wall was certainly a role model for this, as he already had a prominent position in UNIX development circles when Perl was released through other projects such as rn or patch , but now Randal L. Schwartz, Damian Conway, Audrey Tang , Brian Ingerson also count and Adam Kennedy among the leading figures, who get a lot of attention through their work within the "scene". In contrast to commercial programming languages, almost all activities can be traced back to personal motivations. Accordingly, the Perl Foundation is a pure volunteer organization that sees itself as the pivot of a self-governing community and uses the donated money for influential projects and people, the organization of developer conferences and the operation of the most important Perl-related websites.

Meetings, workshops and conferences

Local user groups, who usually invite to casual meetings once or twice a month, at which lectures can also be given, call themselves Perl Mongers and can be found in over 200 major cities around the world. The annual workshops are larger, much more tightly organized and mostly country-specific, of which the well-established German Perl workshop was the first. Workshops want to bring ambitious developers together locally in a framework that is as affordable as possible. The larger Yet Another Perl Conferences (YAPC), which are held for the regions of North America, Brazil, Europe, Asia, Russia and Israel, have a similar goal . The largest, but also the most expensive, is The Perl Conference ( TPC ) organized by O'Reilly in the USA , which is now part of OSCON .

Hackathons have also been held for committed contributors since around 2005 , mostly on the topics of quality assurance and Perl 6.

Disciplines

Many of the language features of Perl invite you to be creative with your code. This has led to various intellectual, sometimes humorous, sometimes bizarre competitions and traditions around the Perl programming language.

golf
Golf is a sport for programmers in which the shortest program (in ASCII characters) that completely fulfills a given task wins. Since Perl knows many, sometimes tricky, abbreviations and abbreviations for common techniques, this is a particularly popular discipline among Perl programmers.
poetry
Since Perl contains many elements of the English language, there are regular competitions in which the best examples of Perl poetry are awarded. In addition to the free form, which only has Perl as its content, an attempt is made here to write poems that are executed by the interpreter without warnings and error messages. There is also a pearl haiku competition dedicated to this Japanese form of poetry.
Obfuscation
The discipline obfuscation is also very famous and notorious , for which there is also an annual competition (the " Obfuscated Perl Contest "), which is most comparable to the International Obfuscated C Code Contest , which Larry Wall himself won twice. The aim here is to disguise the function of a program in an unusual and creative way. This is particularly easy in Perl because there are abbreviations for almost everything, the language itself is very dynamic and many things happen automatically depending on the context, which is often referred to as "Perl magic". An example from Mark Jason Dominus, who won second prize in the 5th Annual Obfuscated Perl Contest in 2000 (this program outputs the text “Just another Perl / Unix hacker”):
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
Randal L. Schwartz
JAPH
A kind of sub-category of obfuscation is the JAPH discipline publicly started by Randal L. Schwartz . These are signatures that contain small Perl programs which usually only output the name of the author or a message in a way that is as incomprehensible as possible. The letters JAPH are the first letters of Schwartz's signature Just Another Perl Hacker.
Perligata
The Perl module Lingua :: Romana :: Perligata by Damian Conway is probably one of the most bizarre modules par excellence: It enables the user to write Perl entirely in Latin . As in the Latin language, the sentence order is (largely) irrelevant for the meaning of an expression; instead, the relationships between individual words are established through their inflection . From variables to references and multi-dimensional arrays, everything is in this new language definition. Almost all special characters have been removed from the language, variables with the same name but different structure ( e.g. $ next and @next ) are declined in order to address the corresponding variable. Some sample code:
insertum stringo unum tum duo excerpemento da.
   # Entspricht: substr($string,1,2) = $insert;
clavis hashus nominamentum da.
   # Entspricht: @keys = keys %hash;
“Language modules” for Klingon , Borg or Leetspeak were created from a similar drive . Such modules are a good example of the amount of time that many people devote to Perl; In this sense, Perl can definitely be called a hobby.
Acme
Brian Ingerson laid the foundation for a CPAN category of modules that have no productive use, often consciously , with his well-known module called Acme , which does nothing more than certify to the user that his program has reached the highest level of perfection are counterproductive or pretend a function that is impossible to achieve in this way and should be understood more as a joke. This game of bizarre ideas includes impressive ASCII art , modules that make the source code invisible (Acme :: Bleach) or manipulate it in some other humorous way, for example by providing it with typical language errors of President Bush or randomly deleting methods that indicate the presence of a supposed to simulate thieving magpie .

Mottos and quotes

Perl programmers see camels of all kinds as mascots. The London Perl Mongers even adopted one from the London Zoo.

There are many well-known mottos and quotes that deal with Perl itself or the possibilities of language; here are some samples:

  • " Perl: the Swiss Army Chainsaw of Programming Languages.
    (Perl: The Swiss Army Chainsaw of Programming Languages. Allusion to the versatility of Swiss Army Knives .)
  • Perl is the only language that looks the same before and after RSA encryption. ”( Keith Bostic )
    (Perl is the only language that looks the same before and after RSA encryption.)
  • Only perl can parse perl. ”( Larry Wall )
    (Only perl can parse Perl .)
  • … We often joke that a camel is a horse designed by a committee, but if you think about it, the camel is pretty well adapted for life in the desert. The camel has evolved to be relatively self-sufficient. On the other hand, the camel has not evolved to smell good. Neither has Perl. ”( Larry Wall : on the camel as a pearl mascot)
    (… we often joke that a camel is a horse that was designed by a committee. But when you think about it, the camel is pretty good at desert life The camel evolved to be self-sufficient. On the other hand, it wasn't evolved to smell good. Neither did Perl.)
  • " The very fact that it's possible to write messy programs in Perl is also what makes it possible to write programs that are cleaner in Perl than they could ever be in a language that attempts to enforce cleanliness " ( Larry Wall : Linux World, 1999)
    (The very fact that it is possible to write dirty programs in Perl makes it possible to write programs that are cleaner than languages ​​that try to enforce cleanliness.)
  • Perl: Write once - never understand again
    (
    Perl: Write once - never understand again . An allusion to the mantra Write once - run everywhere from Java )

Awards

Competitions

literature

Web links

Wikibooks: Perl Programming  - Learning and Teaching Materials
Commons : Perl (programming language)  - collection of images, videos and audio files

Individual evidence

  1. Perl Source on GitHub
  2. Larry Wall: Programming is Hard, Let's Go Scripting… on perl.com of December 6, 2007; accessed on June 1, 2019.
  3. Larry Wall: Perl, the first postmodern computer language , accessed December 31, 2018.
  4. manpage of Perl 1.0 in the Perl timeline . on perl.org (English)
  5. wired interview in issue 8.10 in 2000
  6. The first part of the official Perl FAQ (English)
  7. Table of all release dates of Perl (POD document; English) in the official CPAN distribution
  8. TMTOWTDI in the English-language Wiktionary
  9. Getopt :: Long on CPAN
  10. List of known ports on CPAN
  11. Inline module on CPAN
  12. GNU Octave on gnu.org
  13. Why Modern Perl Teaches OO with Moose . chromatic
  14. Susanne Schmidt: Happy Birthday, Perl! A scripting language celebrates its 30th birthday . In: iX . No. 12, December 18, 2017, p. 108. Retrieved December 25, 2017.
  15. German Perl Workshop .
  16. Perl developers among themselves: The results of the Perl QA Hackathon 2015 .
  17. For example, Perl Poetry Category perlmonks.org (English)
This version was added to the list of articles worth reading on August 26, 2005 .