[an error occurred while processing the directive]
RSS
Логотип
Баннер в шапке 1
Баннер в шапке 2
2023/07/06 22:17:47

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.

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[1]

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