RSS
Логотип
Баннер в шапке 1
Баннер в шапке 2
2024/06/10 22:55:34

Perl

Practical Extraction and Report Language. Created by Larry Wall in 1986, it is usually used to create dynamically genius web pages. It is also used by system administrators and webmasters to work and change texts, files and processes.

Content

Perl is an interpreted language adapted for processing arbitrary text files, extracting the necessary information from them and issuing messages. Perl is also convenient for writing various system programs. This language is easy to use, effective, but it is difficult to say about it that it is elegant and compact. Perl reads the best features of C, shell, sed and awk, so for those who are familiar with them, studying Perl-a will not present much difficulty. The syntax of Perl expressions is close to that of C. Unlike most utilities of the UNIX OS, Perl does not impose restrictions on the amount of data processed and if there are enough resources, then the entire file is treated as one line. Recursion can be of arbitrary depth. Although Perl is adapted to handle text files, it can handle similarly binary data and create.dbm files similar to associative arrays. Perl allows you to use regular expressions, create objects, insert pieces of code on Perl into a C or C++ program, and also allows you to access databases, including Oracle.

This language is often used to write CGI modules, which in turn can access databases. Thus, databases can be accessed via WWW.

2024: Perl 5.40

On June 10, 2024, it became known that after 11 months of development, the release of the updated stable branch of the Perl programming language - 5.40 was published. When preparing the release, about 160 thousand lines of code were changed (without documentation and automatically generated code - 110 thousand), the changes affected 1,500 files, 75 developers took part in the development.

As reported, the 5.40 branch was released in accordance with a fixed development schedule approved eleven years ago, which implies the release of stable branches once a year and corrective releases every three months. Around July 2024, it is planned to release the first Perl 5.40.1 correction release, which will correct the most significant errors identified during the implementation of Perl 5.40.0. Simultaneously with the release of Perl 5.40, support for the 5.36 branch has been discontinued, for which updates can be released in the future only if critical security issues are identified. On June 20, the process of developing an experimental branch 5.41 will begin, on the basis of which a stable release of Perl 5.42 will be formed in May or June 2025, if a decision is not made to move to numbering 7.x.

Key changes:

  • The capabilities associated with the experimental syntax for creating classes that appeared in the previous version have been expanded. The keyword "CLASS" has been added, which, when called from methods, ADJUST blocks, or when fields are initialized, returns the name of the current class, similar to how the keyword "PACKAGE" returns the name of the package. Unlike ref ($ self), the keyword "CLASS" can be used to initialize fields to access class methods before the class instance is completed. For the base class, CLASS is identical to PACKAGE, but will differ when subclasses are created.
  • The attribute ": reader" is implemented for fields defined within the class, which is used to automatically create a method that returns the value of a variable from a field in the current instance of the class. For example, specifying ": reader" after defining the field "field $ s;" is equivalent to creating the method "method s () {return $ s;}." If necessary, you can specify a non-matching method name using a construction of the form "field $ name: reader (get_name);".
  • A stable try/catch exception handling syntax is declared, which can be used instead of non-obvious manipulations with "eval." A "try" block includes a block with executable code and a "catch" block with code to handle any exception that may occur when the first block is executed. In "catch," a variable is defined that contains the data passed when the exception is generated (for example, when the exception is triggered, the string specified as an argument will be passed to the call "die"). Within the "try" and "catch" blocks, transition operators are allowed, including return, goto, next, last, and redo.
  • The syntax "for my (VAR, VAR) (LIST)" and "foreach my (VAR, VAR) (LIST)" has been stabilized, used to search for lists with a one-time extraction of several values ​ ​ at once in one iteration of the loop.
  • A stable builtin module is declared, including the always available functions built into the interpreter. For June 2024, the module offers the functions true, false, weak, unweaken, is_weak, blessed, refaddr, reftype, ceil, floor, is_tainted, trim and indexed.
  • Added experimental built-in functions inf and nan, available in the namespace "builtin::" ("builtin:: inf" and "builtin:: nan"). You can use these functions as constants that define infinity and a non-numeric value.
  • The logical operator "^^" has been added, corresponding to the XOR operation and complementing the bit operator "^" (Perl provides three basic bit operators "&," "|" and "^" corresponding to the AND, OR and XOR operations, but only the AND ("& &") and OR ("| |") options have been available for logical operations so far). The logical expression "$ x ^^ $ y" will return TRUE when either "x" or "y" are TRUE, but not simultaneously.
  • Support for simulating versions up to 5.11 has been discontinued. Using the "use version number" directive, which disables additional features added in the interpreter after the specified version, with a version number less than 5.11 (for example, "use v5.8") will now result in an error, not a warning. Similarly, the warning output when used in version less than 5.39 is added (warnings will be replaced with an error in release 5.44).
  • It is allowed to use a space between the command line option "-M" and the module name, for example "perl -M Data:: Dumper = Dumper -E 'say Dumper [1,2,3]'" (previously it was necessary to write "perl -MData:: Dumper...").
  • Declared obsolete the use of the "goto" operator to move from the outer scope to the inner scope. Support for this feature will be discontinued in Perl 5.42.
  • The main composition includes Term:: Table and Test2::Suite modules designed to create unit tests. Обновлены версии модулей Archive::Tar, Compress::Raw::Bzip2, Compress::Raw::Zlib, Data::Dumper, DB_File, File::Compare, File::Find, Getopt::Long, Hash::Util, HTTP::Tiny, IO, Math::BigInt, PerlIO::encoding, Tie::File, Time::HiRes и т.п.
  • Added support for the Serenity OS operating system.

Two vulnerabilities have been fixed:

  • CVE-2023-47038 - writing outside the buffer when processing incorrect Unicode properties defined by the user. The problem can lead to a buffer overflow of 1 byte when processing specially designed regular expressions.
  • CVE-2023-47039 - the ability to replace an executable file on the Windows platform due to the search for cmd.exe in the paths using the PATH environment variable, in which the current working directory is higher priority than the system directory with the cmd.exe executable[1].

2023: Perl 5.38.0

On July 3, 2023, it became known that after 13 months of development, the release of the stable branch of the Perl programming language - 5.38 was published. When preparing the release, about 290 thousand lines of code were changed, the changes affected 1,500 files, 100 developers took part in the development.

Perl 5.38.0

As reported, the 5.38 branch was released in accordance with a fixed development schedule approved ten years ago, which implies the release of stable branches once a year and corrective releases every three months. In about a month, it is planned to release the first corrective release of Perl 5.38.1, which will fix the most significant errors identified during the implementation of Perl 5.38.0. Simultaneously with the release of Perl 5.38, support for the 5.34 branch was discontinued, for which updates can be released in the future only if critical security issues are identified. The process of developing the experimental branch 5.39 has also begun, on the basis of which a stable release of Perl 5.40 will be formed in May or June 2024, if a decision is not made to move to numbering 7.x.

Key changes:

  • An experimental syntax is proposed for creating classes in which fields and methods bound to each instance of the class can be determined. Classes extend the ability to work with objects in Perl and allow you to use syntax closer to other programming languages ​ ​ (previously, the similarity of the object model in Perl 5 was based on the application of a hierarchy bound to package names).
  • The definition of classes is similar to the creation of packages using the "package" block, except for the need to initialize the class with the launch of the constructor ("my $ object = My:: Class- > new (% arguments);") to create a separate instance of the class, which is subsequently worked with. To execute its code during initialization, an "ADJUST" block is proposed, resembling a "BEGIN" block. Classes can be inherited using the ": isa" attribute.
  • Variables defined within the class using the "field" keyword are visible only within the class - a separate field store is created for each instance of the class that does not intersect with other instances of the same class. Methods allow you to define functions that work in the context of a class.

use feature 'class';

class Example::Base { field $x;

ADJUST { $x = "Hello, world"; }

method print_message { say $x; }


}

class Example::Subclass :isa(Example::Base) { ... }

Example::Base->new->print_message;

  • You have added a binding to subcategories that can be turned off individually to warnings when you use outdated features in your code. For example, you can specify "no warnings' deprecated:: goto_construct '" to disable the warning when using the goto construct, but to keep the remaining warnings.
  • The service hash "% {^HOOK}" has been proposed, which allows you to create wrapper functions for keywords. In the current form, two wrappers are available for definition - "require __ before" and "require __ after," which allow you to bind handlers called at different stages of processing the "require" keyword.

my $old_hook = ${^HOOK}{require__before}; local ${^HOOK}{require__before} = sub { my $old_hook_ret; $old_hook_ret = $old_hook->($name) if $old_hook; warn "Requiring: $name\n"; ... };

  • Added a PERL_RAND_SEED environment variable through which you can set your seed for the pseudo-random number generator (for example, to achieve repeatable behavior during testing).
  • Added support for "//= "and"||= "to define default values for function arguments. The value set through the "//= "operator is used if the argument is not defined (undef), and the"||= "operator is used if the argument contains a boolean value of" false "or is missing).

sub foo ($name //= "world") { print "Hello, $name"; } sub foo ($x ||= 10) { return 5 + $x; } foo (undef);# will be output "Hello, world"

  • Specification support Unicode has been upgraded to version 15.0.
  • In some cases, within blocks "defer" (deferred blocks executed at the very end) and "finally" (block with code executed at the very end of the try/catch construction), the use of the "goto" operator is allowed. Goto is allowed only when using permanent transition labels that do not go beyond the block.

use feature 'defer';

defer { goto LABEL; print "This does not execute\n"; LABEL: print "This does\n"; }

  • At the compilation stage, an invalid exit from the defer or finally blocks is detected using return or goto operations. Previously, such prohibited manipulations were detected only at the time of execution of the problem code, and now the error is displayed immediately.
  • To execute code blocks inside the regex template, the "* {...}" construct was added, which is equivalent to the "? {...}" and "?? {...}" constructs, except that its use does not disable optimization in the regular expression engine, which increases performance, but behavior becomes less stable.

"good" =~ /g(?:o(*{print "o"}))*d/;

  • The size of regular expression quantifiers (REG_INF) is increased from 65,536 to 2 147 483 647 (c U16_MAX to I32_MAX), which allows the use of constructs of the form "/(?: word) {1000000 }/. "
  • Added optimize_optree and finalize_optree functions for working with fragments of the internal structure optree.
  • The regular expression engine implements the variable ${^LAST_SUCCESSFUL_PATTERN}, with which you can access the last successful template.

if (m/foo/ || m/bar/) { s/${^LAST_SUCCESSFUL_PATTERN}/PQR/; }

  • Added support for the LC_NAME locale category, which can be specified when calling "setlocale."
  • Changes that violate compatibility: The readline () function and the ""statement <>have stopped clearing flags that indicate the end of the file or error after a thread processing error. INIT blocks terminated after exit () is called in the BEGIN section.
  • Declared obsolete the use of the character "'" as a package name separator[2]

2010: Perl 6

Perl language creator Larry Wall gives an annual public speech on progress in developing his brainchild. In 2010, the performance took place at the O'Reilly Open Source Convention, and Wall hinted in his speech that the sixth, thoroughly updated version of Perl, which has been under development for about ten years, may finally be released soon.

As in previous years, Wall showcased a number of new Perl 6 capabilities.

For example, if you set the language to a sequence of digits, it is able to guess the next number in the series. So, the command "(1,3,5,7,.... *)" will return a set of 20 odd numbers, starting with one, and on the command "(1,2,4,.... *)" a sequence of powers of two will be issued.

Wall speculated about whether Perl 6 would become a "breakthrough technology." In his opinion, this term is now so often used that it practically lost its meaning, but still it deserves to exist. According to Wall, "breakthrough technology" can be defined as superior to existing ones, even if it is somewhat inferior to its predecessor.

Wall is convinced that early versions of Perl became breakthrough for the Unix community, since they did not follow the original ideology of this operating system "to do one thing, but to do well." Perl developers are proud to emphasize that Perl can solve any problem in several ways.

The disadvantage of the Unix approach, according to Wall, is that in reality only a few of the utilities of this operating system performed their functions perfectly.

"They were all full of artificial constraints," Wall opined. - System administrators had to spend a lot of effort to coordinate the data format between the two utilities for any operation, and each such operation inevitably led to the creation of a mass of small files scattered throughout the directory. Perl is able to bypass the Unix shell, leaving data in the program itself. "


According to a study presented by the analytical company W3Techs at the end of 2011, the use of the Perl programming language on web servers fell below 1%. Once the most popular scripting language, Perl ranks only fifth in popularity with a share of 0.997%.

According to W3Techs experts, this share corresponds to the use of Perl on sites, the number of which is measured in millions, which is "not bad at all," given that web servers based on Ruby and Python occupy less than 1% on the Web.

W3Techs experts also note a small but very significant trend, in their opinion,: recently 4.1% of sites with Perl have been translated into PHP, but at the same time 2.7% of all sites with Perl support used the PHP language until recently.

Programming languages

Notes