Perl is a high-level dynamic, procedural, and interpreted programming language created in 1987 by Larry Wall. Perl has inherited a unique set of features from C, Unix scripting shell (sh), Awk, sed, and to varying degrees from many other programming languages, including some functional languages.
Description
Although known as a CGI development language, Perl was originally created as a tool for systems engineers, as a language for text and file manipulation. In fact, it is also called practical extraction and reporting language, but this is an inverted acronym. Therefore, according to the Perl documentation itself, you should never refer to it as “PERL”, but as “Perl” or “perl”, depending on whether you mean the language as such or a specific implementation, respectively.
It has evolved over time, thanks in part to a powerful system of modules, into a more general language, including image processing, database queries, network communication processes and can be used in all those areas where the performance of a language is not strictly required on a compiled at a lower level, which also provides much faster development times. It is therefore also used for the prototyping of programs to be implemented in other languages.
The language was meant to be practical; it was never designed to be compact, elegant or minimal, in fact the motto is summed up in the acronym TMTOWTDI (There is more than one way to do it), which in Italian means very indicative “there is more than one way to do it”. Larry Wall said that Perl’s goal is “to make things easy, easy and difficult” (“Make the easy things easy and the hard things possible.”).
Perl supports both procedural and object-oriented paradigms, has powerful word processing functions, and is equipped with one of the largest collections of modules produced by its large user community.
Functions
If at first glance Perl appears to be largely derived from C, it has indeed acquired this similarity mediated by shell scripting languages. Perl is a typeless procedural language with variables, expressions, assignments, brace-separated blocks, control structures, and subroutines. The latter can be understood as functions and Perl has numerous qualities mediated by functional languages.
Variables have a prefix ($ for scalar variables, @ for array, % for hash) called a seal and if this partially determines Perl’s syntactic richness, it allows the interpolation of variables into strings. Like Unix shells, Perl comes with many standard features for common tasks such as sorting and accessing the operating system. (Actually only 279 in the main core of perl, versus over 3000 in PHP).
Perl took associative vectors (known as “hash”) from awk and regular expressions from sed. These greatly simplify and facilitate the parsing and processing of text and data.
There is also the option of integrating C code into a Perl program and vice versa (adding or rewriting parts in C/C++ in Perl applications or packages, or inserting an embedded Perl into C programs). Actually with the Inline modules:: there are multiple languages in which the functions of a Perl source can be defined. Some mail programs are: hotmail, gmail, yahoo mail and proximus mail.
Perl is often thought of as an interpreted language, meaning that in order to be executed, it is interpreted at the time of execution. In reality, the first thing the interpreter does is convert the source code into byte code, a bit like Java; on the bytecode it creates an intermediate graph on which it applies optimizations, and it is this graph that needs to be interpreted. This approach makes it possible to limit the slowness typical of interpreted languages. The version of Perl 6 [6], which has been in development for several years, separates the executor from the bytecode (or virtual machine) of the language in such a way that it can also be used by compilers of other languages, including Tcl, Python, Java, etc.
The resulting virtual machine will provide a new foundation for the development of free languages and will allow a very high degree of optimization and independence of the development of the parent languages. Although Perl 6 has not yet been released, some ideas have leaked in the stable version of Perl 5.8 and many others will have a match in Perl 5.10. A prototype of Perl 6, called Pugs, has been developed in Haskell and an interesting mutual fertilization is taking place between the two communities (Perl and Haskell).
It has been emphasized again how Perl is a “cozy” language, which therefore tends to interact with other languages and development environments, be they: shell dialects, other interpreted languages, specialized languages (such as SQL) or the most common compiled languages. This is why Perl is successful in integrating different systems.
Perl was born in a Unix environment and was distributed simultaneously with two liberal licenses, the GPL and the Artistic License. It is also available for Microsoft Windows and MacOS operating systems prior to the Mac OS X version (which belongs to the Unix family). The most widespread implementation for Windows is distributed by a company, ActiveState, which offers specific modules for the Windows operating system under a free license and sells integrated development environments for both Perl and other languages. source such as Python and Tcl.
While Perl was one of the great innovations in programming, the judgment of the programming community on it has varied:
on the one hand, it is rated negatively for facilitating the writing of hard-to-read programs and therefore complicating its maintenance (to the point that the language’s name has been reinterpreted as Pathologically Eclectic Rubbish Lister);
on the other hand, it is valued for the ease with which powerful yet simple programs can be written, and for the semantic freedom it leaves to the programmer to the point that “there is no one way to do things” is one of the idioms that associated with Perl.
Wall – who is a linguist by training – considers this semantic freedom a virtue, because it is more like human language. Another positive aspect that attracts programmers is the wide availability of modules distributed with open source licenses, almost always the same as Perl. Modules are usually well documented, as the language itself provides the Pod, a way to code the documentation so that the documentation belongs to the module. The community has created a special site called CPAN that organizes the modules considered particularly valuable by topic. The modules themselves are not stored on that site, but remain on the sites chosen by their authors. Finally, as an interpreted language and therefore always distributed with visible source code, it prefers liberal practice.
Other key features of Perl include:
- default variables defined for many perl built-in functions and operators
- the sensitivity of the context in the commands, where Perl knows what to return based on the linker value
- regular expressions, which allow the search and replacement of text strings described with special characters
- closures
- the ability to apply different programming paradigms, such as functional or object-oriented.
Some features of Perl, including the syntax, allow a synthesis that is rarely possible with other languages and impossible with languages like Java and the resources can therefore have very close meaning, so much so that they are cryptic to those those who don’t know the principles. On the other hand, there is so much documentation about Perl on the internet that it is possible to quickly access the language and start the learning path with appropriate reference texts.
The language and interpreter were developed by a group of about a hundred developers, led by Wall, who make the final decisions about what to include in the code. The developers created the Perl Institute to facilitate the development of Perl and improve its visibility and organize conferences. Wall himself works for O’Reilly, a publishing house that actively supports the Open Source movement.
Perl is part of the standard tools of Unix operating systems. The update can be done through the Internet as well as through the distributions of free operating systems, such as GNU/Linux, BSD, etc. Windows versions can also be downloaded from the Internet. Some Perl manuals come with a CD-ROM containing versions for different operating systems and all modules in the CPAN.
The Perl community is often attacked for the absence of an IDE, such as the one present for Java, which makes it easy for newcomers to access the language. In reality, the expressive richness of Perl makes it difficult to create an IDE that emphasizes construction errors in the instructions, and given the many default values of the basic functions, it would be extremely difficult to automatically understand what the programmer wants to achieve, where there is a wrong, or maybe not. However, Eclipse includes an extension for Perl and perhaps other code editors will follow.
Sample programs
Read the standard entry in CSV format and print the 2 initial fields
! /usr/bin/perl
#with fields you can do whatever you want
while (<>) {
my @ field = split /, /;
print "$field[0], $field[1]\n";
}
In this example, there are some default settings that cannot be understood without explanation:
<> is a synonym for which in turn is an iterator on a special file handle pointing to the files specified on the command line if any or to STDIN else and denotes the action of extracting a line from that file handle . This line is inserted, without further instructions, into $_, a predefined variable that many operators and functions work on by default.
split takes a pattern (regular expression) and, unless otherwise specified, acts on the variable $_, breaks at the points where the pattern matches, and returns the remaining pieces.
The same program can be rewritten in the following form:
! /usr/bin/perl
while (<>) {
my($field1, $field2) = split /, /;
print "$field1, $field2\n";
}
In this second case we see how it is possible to write the same program in a different way. There are many other writings of the same short program.
Note: the my statement isn’t strictly necessary unless you’re using the strictly pragmatic module, but the latter is recommended by the vast majority of perl programmers, along with caveats, because it restricts the programmer’s freedom in ways that avoid errors . common programming practices, enforcing more disciplined programming practices imposed by default in other languages.