Perl (language)


Perl 3 is a programming language created by Larry Wall in 1987 to easily handle the type of information text . This language, interpreted , is inspired by the control and printing structures of the C language , but alsoscripting languages sed , awk and shell ( sh ).

It supports regular expressions in its very syntax, thus directly allowing actions on the general appearance of text sequences.

An association, The Perl Foundation , is concerned with its future, including its possible change from version 5.x to version 6. The status of the language is that of free software , distributed under dual license : Artistic License and GPL .

Origins and implementations

The goal

Perl provides a convenient way to extract text and report information from text files . It can replace shell scripts as well as commands like sed , awk , grep , cut , test and expr . Processing input formats that are not necessarily structured, it avoids the need to pass data from one process to another and thus render processing less treatable, providing a unified framework. Its syntax is inspired by C, adds the possibility of regular expressions directly in the language, and includes the main functions of the system libraries in C.

It also seeks pragmatic convenience for the programmer (there are shortcuts that make the call “diagonal” language) rather than a strictly aesthetic architecture desire ( “orthogonal” languages) 4 .

The means

Perl, cross-platform , is used inter alia for writing CGI scripts and processing log files. It also allows you to add ” in-process ” in a server web Apache, thanks to the extension mod_perl , like PHP or servlets Java .

It is easily found or compiled on most operating systems , including POSIX ( Linux , * BSD , Mac OS X , Cygwin on Microsoft Windows with ActivePerl (version 5.8 allows the use of Unicode or Of the graphical interface) and Cygwin.
Since the availability of WSL under Windows 10, it can also be used in a window bash under Windows.

Since 2008 exists strawberry 5 for Windows, close to the original Unix distribution, with a C compiler .

Syntax and semantics

Perl is an imperative language close to C and UNIX shells . As in shell, the hash character (#) introduces a comment . The syntax of Perl allows her to express concisely in the same language expressions without calls functions libraries , so more legibly. The beginner can easily use only a subset of the language.

Perl is statically typed simply: the first character of an identifier tag is a non-character alphanumeric called sigil . Like the Unix shells, the dollar sigil ($) denotes a variable scalar , the sigil at sign (@) is a variable table and the sigil percent (%) an associative array , also known as hash or hash . Arrays can be used as stacks or queues , common to javascript .

Print "Hello, world \ n" ;

Perl accepts reporters indicating the scope of the declared variables:

My $ s = 'toto' ; # Scalar variable with
local lexical range $ level + = 1 ; # Scalar variable with a value in dynamic range
our @s = ( 1 , $ s , 3.14 ); # Variable global array to current module

Sigils allow you to recognize variable names in strings and interpret these variables.

 Print "the toto variable is $ toto" ;

Perl does not require manufacturers of bodies .

 my % y = ( cl e 1 => [ 1 , 2 ], cl e 2 => [ 3 , 4 ] );

The XML :: Literal  [ archive ] module available on CPAN supports XML type literals in a manner similar to ECMAScript’s E4X standard extension .

Version 5.10

Since version 5.10, the language includes features for the future Perl 6, such as a switch control structure and named captures for the match operator (ie the ability to generically name items processed on the fly) . The 6 th version of the language, announced since 2001, still awaits its full completion in 2016.

Integration into the existing

Perl programs are fully portable between GNU / Linux , Mac OS X (or other UNIX ) and Windows despite the different file designations of these systems (Perl replaces “/” with “\” or “\\” “). This language was used as a CGI script to run Wikipedia until January 2002 [ ref.  Desired] .

Perl allows the use of motor GUIs Tk to perform input-output. The set is sometimes referred to as the generic name Perl / Tk . The Tk extension is included in ActivePerl since version 5.8 of the language.

Graphical interfaces that are more convenient than Tk are also available from CPAN libraries .

TkZinc brings a modernized look to Tk. PerlQt supports Qt 3.x. Gtk2 supports Gtk 2.x. Wxperl supports wxWidgets . WxWidgets has the advantage of providing the native appearance of the windowing system used. In Mac OS X , CamelBones gives access to the Cocoa API .

The mechanism

Perl5, although interpreted, does not reanalyze his instructions whenever he executes them. Without creating a bytecode like other interpreted languages, it performs an assembly pass that translates constants, replaces variables with internal addresses, and constructs an abstract syntax tree (AST ).

The source code is translated instruction by AST instruction, subsequently optimized. If instructions are located in a special block such as BEGIN or CHECK , they are executed as soon as they are compiled (and thus before the rest of the source code is compiled). This is particularly the case for modules loaded by the use statement . The AST, with respect to a usual AST, has the particularity of already containing the execution paths. During the execution phase, the interpreter follows the paths present in the AST and executes the remaining instructions 6 .

Perl 5 does not use bytecode at any time. The project of compilation in bytecode started during Perl 5.005 by Malcom Beattie has never succeeded. The arrival of Parrot can however offer a new solution.

The future in the medium term

Several functionalities of the Perl 5 libraries will be integrated in Perl 6: thus syntactic analysis will be integrated into the regular expression engine. Today, in Perl 5, an LALR parser can be written by the Parse :: Yapp  [ archive ] module , the yacc clone . Parse :: RecDescent  [ archive ] is a module that allows the writing of a descending recursive parser.

Code examples

A recurring joke like this Perl short for Pathologically Eclectic Rubbish Lister ‘( pathological collector of mixed waste ) in reference to its special character full of meaning in the syntax of the language, as in the following example:

# An example program in Perl
$ message = "At the location: 'camel'. \ N" ;
Print $ message ;
$ Message = ~ s / place / back / ;
$ Message = ~ s / ('\ w +') / reverse ($ 1) / e ;
Print $ message ;
Exit 0

And its output on the screen:

In the place: 'camel'.
Upside down: 'lemac'.

The third and fourth lines of this example show the use of regular expressions .

These special characters are related to the processing power of Perl:

  • Scalars denoted by $ : $ name = “Toto”; $ Z = 3;
  • Tables denoted by @ , indexed by [] : $ name [95] = “Val d’Oise”; ( $ Because this 96 th array element is like the other a scalar !)
  • Associative arrays or hashs denoted by % , indexed by {} : $ code {“Val d’Oise”} = 95; ( $ Because their elements are scalars too)

Fake friends

Some words have a different meaning in Perl and in the usual computer literature. Here are two examples:

  • A function (function) is a function predefined by the language;
  • A routine , also called sub-routine ( subroutine in English), is a function defined in the program or a library used.

Community aspects

Perl has a large user base, but is increasingly competing with PHP , Python , Ruby , Javascript , and more. The language is appreciated by system administrators but also by developers in the field of bioinformatics where programs are constantly being revised 7 .

The CPAN database brings together 15.4 million lines of code n 1 in the form of Perl modules and synopsis showing how to implement them.

In France, Perl’s Mongueurs promote this language, especially via the Perl Days .

Anecdotes

We usually write the name of this language with a capital P to designate the language and a minuscule p by speaking of the interpreter : “only perl parses Perl correctly. One consequence is that a syntax highlighting system of a Perl program should use the perl interpreter to be completely correct. In practice, pure Perl modules such as Perl :: Tidy  [ archive ] and PPI  [ archive ] can correctly understand most of the current code.

Initially, the designer of Perl, Larry Wall , had planned to name his “language pearl ” according to a parable biblical being told in the Gospel of Matthew (chapter 13, verses 45 and 46, 8 ). There was already a programming language called PEARL – for multitasking and real-time programming. Wall changed the spelling to “Perl” 9 . The various meanings we find today as the Practical Extraction and Report Language are simply retroacronyms . [Ref. necessary]

Black Perl is a poem signed by Larry Wall, written in the Perl programming language and in the English language. It is a nod to the film Pirates of the Caribbean .

Software written in Perl

  • Various libraries [Which?] Covering the continuum of content management systems , wikis and blogs . Perl is at the heart of sites like Slashdot , LiveJournal …
  • GNU Automake , software generating portable makefiles
  • Fink , an open source project designed to bring applications originally written for UNIX to Mac OS X
  • SVK , code version management system. This is an extension of Subversion
  • Movable Type , a publishing platform for companies, used by companies such as General Motors
  • Blosxom , blog software and a content management system
  • Sympa , mailing list manager
  • SpamAssassin , anti-spam email filter
  • Bugzilla , bug manager
  • Webmin , software for configuring a machine via a web interface
  • Urpmi , Mandriva Package Manager and Mageia. Their installers and their configuration tools are also written in Perl
  • Frozen Bubble , arcade game
  • AWStats , log analyzer
  • Of IRC bots are written in Perl (infobot) or provide Perl interfaces (eggdrop)
  • Koha , first SIGB under free license
  • MRTG , network monitoring software
  • Stormons, monitoring software for SAN and NAS

Appendices

Bibliography

General information
  • Larry Wall, Tom Christiansen and Jon Orwant, Programming Perl , 3 th edition, 2001 ( ISBN  2-84177-140-7 ) ( fourth updated edition in English only published in 2012)
Recent works in French
  • Philippe Banquet, The Fundamentals of Perl Language 5: Learning by doing , Editions ENI, 2013 ( ISBN  2-74607-932-1 )
  • Sébastien Aperghis-Tramoni Philippe Bruhat, Damien Krotkine Jerome Quelin, modern Perl: Most of the current practices , Pearson, 2010 ( ISBN  2-84177-140-7 )
Applications
  • James Tisdall, Introduction to Perl for Bioinformatics , O’Reilly, ( ISBN  2-84177-206-3 )

Notes and references

Notes

  1. ↑ In July 2004.

References

  1. ↑ http://www.nntp.perl.org/group/perl.perl5.porters/2017/01/msg242259.html  [ archive ]
  2. ↑ http://www.nntp.perl.org/group/perl.perl5.porters/2017/02/msg243172.html  [ archive ]
  3. ↑ Perl is not an acronym, according to the official documentation.
  4. ↑ ( en ) ” For and foreach … [ archive ] .
  5. ↑ [1]  [ archive ] Strawberry Perl.
  6. ↑ ( en ) ” perlmod [ archive ] , perldoc.perl.org.
  7. ↑ ( en ) ” Perl and Bioinformatics [ archive ] , perlmonks.org, February 15, 2010.
  8. ↑ French Bible Society – Bible • Mat. 13:45 and 46  [ archive ] .
  9. ↑ ( in ) Marjorie Richardson , ” Larry Wall, the Guru of Perl [ archive ] , on Linux Journal  (en) , (Accessed 16 January 2016 )