What is Perl? Detailed introduction to programming language Perl

Time:2021-12-26

Perl was originally designed by Larry wall and was published on December 18, 1987. Perl borrows features from C, SED, awk, Shell Scripting, and many other programming languages. Larry wall is on the newsgroup comp sources. Misc released Perl scripting language version 1.0, when he was a programmer at Unisys. Perl draws lessons from the characteristics of scripting languages such as sh, awk and sed, and tries to become a general UNIX scripting language that can simplify report processing.

What is Perl? Detailed introduction to programming language Perl

Perl 2 was released in 1988 with more features and a better regular expression engine. Perl 3 and Perl 4 were released in 1989 and 1991 respectively, while Perl 5 released in 1994 is the most important version and is still under development. Perl 6, launched in 2000, completely rewrites Perl. Based on different principles, developers decide to formulate language specifications first. The release date of Perl 6 is considered Christmas, but no Christmas is specified. Perl 5 released 16 versions. Perl 5.6 was released in 2000. The continuous development of Perl 5.8 ran through 2002-08, 5.10 was released in 2007, and 5.12 was released in 2010. Since then, Perl began to release a version every month, a stable version every year, 5.14 in 2011, and 5.16 in 2012.

Perl is generally called “Practical Extraction and report language”, although it is sometimes called “pathologically eclectic garbage Lister”. It’s a term, not just a shorthand. Larry wall, the creator of Perl, proposed the first one, but soon extended it to the second. That’s why “Perl” doesn’t have all the letters capitalized. There’s no need to argue which one is right. Larry agrees with both. You may also see “Perl”, all letters are lowercase. Generally, “Perl”, with capital P, refers to the language itself, while “Perl”, with lowercase P, refers to the interpreter of the program. The official website of Perl is www.perl.com org。

Perl features
Perl interpreter is an open source free software. You don’t have to worry about the cost of using Perl. Perl can run on most operating systems and can be easily migrated to different operating systems.

Perl is a language that can accomplish tasks. From the beginning, Perl was designed to simplify simple work without losing the ability to deal with difficult problems. It can easily manipulate numbers, text, files and directories, computers and networks, especially the language of programs. This language should be easy to run external programs and scan the output of these programs to get things of interest, and it should also be easy to hand over these things of interest to other programs for special processing. Of course, this language should also be easy to compile and run on any modern operating system.

Perl basic syntax
Scalar definition, starting with the $sign, such as: $num = 1;

Array definition, starting with @, for example: @ array = (1,2,3);

The array element calls @ array [index], where index represents the array subscript. As in the above example, the value of @ array [0] is 1

Hash definition, starting with%, for example:% hash = (“a”, 1, “B”, 2);

Hash call% hash, where key represents the key value. As in the above example, the value of% hash {“B”} is 1

What is Perl? Detailed introduction to programming language Perl

Philosophy of Perl
Perl pursues simplicity and solves a general problem with a few lines of code A slightly more complex problem code will not exceed one screen! In fact, most programs written in Perl do not exceed 100 lines

Perl was originally designed as a glue language for UNIX, but it has long been transplanted to most other operating systems. Because Perl can run almost anywhere, Perl is arguably the most portable programming environment today. To write portable C / C + + programs, you have to add a lot of #ifdef tags to distinguish different systems. To write portable Java programs, you must understand the characteristics of each new Java implementation. To write a portable shell, you may have to remember the syntax of each command on each operating system. When you are lucky, you may find some common things. To write portable visual basic programs, you only need to have a more flexible definition of “migration”.

We are glad that Perl avoids all these problems while retaining many of the advantages of these languages and some of its own features. Perl’s features come from many aspects: its feature set, tools, the creativity of the Perl community, and the environment of the open source movement. However, many of these features are mixed things; Perl’s life is complex. It always sees things as different aspects of strengths, not weaknesses. Perl is the language of “I’ll take the blame”. If you feel like you’re in a mess and crave freedom, use Perl.

Perl is cross-cultural. Perl’s explosive growth is largely due to the desire of former UNIX system programmers to bring as much as possible from their “Hometown”. For them, Perl is a portable UNIX cultural distiller and an oasis in the desert where “this road is impassable”. From another perspective, Perl can run in another direction: web designers working on windows are usually very happy to find that their Perl programs can run on UNIX servers without modification.

Although Perl is very popular among system programmers and web designers, it is only because they first discovered Perl, which can be used for a wider range of purposes. From the earliest text processing language of Perl, it has developed into a very complex and universal languageprograming language, and a complete development environment, including debuggers, regulators, cross references, compilers, libraries, syntax prompt editors, and all the hooks of all other “real” programming languages, as long as you need them. Of course, these are things that make it possible for us to deal with difficult problems, and many other languages can do this. Perl becomes Perl because it never loses other features by keeping things simple.

Because Perl is powerful and easy to use, it is widely used in all aspects of daily life, from aerospace engineering to molecular biology, from mathematics to linguistics, from graphics processing to document processing, from database operation to network management. Many people use Perl to quickly process large quantities of data that are difficult to analyze or convert. It doesn’t matter whether you are dealing with DNA sequences, web pages, or the future of pig belly. In fact, there is a joke in the Perl community that the next stock market crash is likely to be caused by bugs in the script written by a guy. (on the bright side, however, any unemployed stock analyst still has something to take advantage of.)

There are many reasons for Perl’s success. Perl was a successful open source project long before the name of open source software appeared. Perl is free and will be free forever. You can use Perl in any suitable situation, just abide by a very free copyright. If you’re in business and want to use Perl, use it. You can embed Perl into your business software without paying any fees or restrictions. If you encounter a problem that cannot be solved by the Perl community, you also have one last move: the source program itself. The Perl community will not rent you their trade secrets under the disguise of “upgrading”, and the Perl community will not “close down”, let alone leave you alone.

Perl is free software, which is undoubtedly helpful to it. But this is not enough to explain the Perl phenomenon, because many free software packages have not prospered. Perl is not only free; And fun. People feel that they can be creative in Perl because they have freedom of expression: they can choose whether to optimize the computer speed or the programmer’s speed, whether to be verbose or concise, whether to choose readability or maintainability, or choose reusability, portability, acceptability and impartability, etc. If you enter a fuzzy Perl competition, you can even optimize for fuzziness.

Perl can give you all these freedoms because it is a language with a split personality. Perl is also a very simple and rich language. Perl takes good ideas from elsewhere and installs them into an easy-to-use framework. For those who just like her, Perl is a practical extraction and report language. For those who love her, she is a pathologically electric garbage Lister. In the eyes of a few people, Perl is meaningless repetition, but the world needs a little redundancy. Minimalists always want to separate things, and we always try to combine them together.

Perl is a simple language for many reasons. For example, you don’t need to know any special instructions to compile Perl programs — just execute it as a batch or shell script. Perl’s types and structures are easy to use and understand. Perl has no restrictions on your data — your strings and arrays can be as long as you have enough memory, and they all grow automatically. Perl won’t force you to learn new grammar and semantics. Perl borrows grammar from many other languages you are already familiar with (such as C, awk, basic and python, English, Greek, etc.). In fact, any programmer can read its meaning from well written Perl code snippets.

Most importantly, you can start writing useful programs without learning everything about Perl first. You can write very small Perl programs. You can also write Perl programs like a child. We promise we won’t laugh at you. Or more precisely, we will never laugh at children’s creativity in doing things. Many ideas in Perl are borrowed from natural languages. One of the best ideas is that you can use a subset of these languages as long as you can express your meaning clearly. Perl culture can accept members of any proficiency level. We won’t put a language policeman behind you. If your boss doesn’t fire you and your Perl script can do the job, it’s “right”.

Although Perl is very simple, it is still a language with rich features. If you want to use those features, you have to learn something, which is also the tuition fee to make the problem simple. Although it will take some time to absorb all the things Perl can do, you will be very happy to find that Perl can do these things when you need these functions.

Due to Perl’s inheritance, even when it is only used as a data induction language, Perl has rich features. From the beginning, Perl is designed to browse files, scan a large amount of text, generate dynamic data and print well formatted reports of these data. However, then Perl became popular, so it became a language that can operate file system, process management, database management, C / s programming and security programming, web information management, and even object-oriented and function-oriented programming. Moreover, these functions are not only in Perl. Each new function communicates well with other things. Don’t forget that Perl was designed as a glue language from the beginning.

And Perl doesn’t just stick to its own features. Perl is a language designed to be extensible with modules. You can use Perl to quickly design, write, debug and deploy Perl applications, and you can easily expand these applications when you need them. You can embed Perl in other languages, and you can embed other languages in Perl. Through the module input mechanism, you can treat these external extensions as built-in Perl features. Those external object-oriented libraries remain object-oriented inside Perl.

Perl also helps you in many other ways. Unlike strict command files and shell scripts that execute one command at a time, Perl first quickly compiles your program into an internal format. Like any other compiler, this time also carries out various optimizations and feeds back to you any problems encountered. Once the Perl compiler front end is satisfied with your program, it will hand over the intermediate code to the interpreter for execution (or to other module back ends that can generate C or bytecode). It sounds complicated, but Perl compilers and interpreters are quite efficient. Our compile run modify process is almost in seconds. Coupled with many other development features of Perl, this rapid role transformation is very suitable for rapid prototyping. Then, as your program matures, you can gradually tighten the nuts on the tight fitting to reduce loose and enhance the rhythm. If you do well, Perl can help you.

Perl can also help you write safer programs. In addition to the typical security interfaces provided by other languages, Perl also provides you with protection against accidental security errors through a data tracking mechanism, so that you can prevent disasters before they occur. Finally, Perl allows you to set up a special protection interval to run Perl code from unknown sources, so as to eliminate dangerous operations.

However, a little paranoid, most of what Perl helps you has nothing to do with Perl itself, but with the people who use Perl. Frankly, people in the Perl community are arguably the most enthusiastic people on earth. If the Perl movement has a little religious color, then this is its core. Larry wants the Perl community to work like a small piece of paradise. At present, it seems that his wish has basically come true. We also ask you to make your own efforts for this.

Perl is powerful because of cpan, which has countless open source modules, from scientific computing to desktop applications to the network and so on! And now there are countless people in the world adding modules to it! If you want to implement a function with Perl, you don’t have to do it yourself. Search cpan and you will probably get the existing results! Cpan (the comprehensive Perl Archive Network) is the central repository for finding anything Perl related. It contains wisdom gathered from the entire Perl community: hundreds of Perl modules and scripts, documents equivalent to several books, and the entire Perl release. If something is written in Perl and it is useful and free, it is likely to be on cpan. Cpan has a mirror image all over the world. You can find it in http://www.perl.com/CPAN Find the mirror closest to you on the cpan road sign. The road sign will remember which mirror you chose and you will visit it later http://www.perl.com/CPAN/ (note the last slash) will automatically redirect to the image. In addition, you can also go to www.cpan.com Org start. The interface of this station is different, but the data is the same.

What is Perl? Detailed introduction to programming language Perl

Perl culture
1. Times make heroes
In order to understand why Perl is defined as it is now (or why it is not defined as something else), we must first understand why Perl exists. So let’s dig out the dusty history book first

Back in 1986, Larry was a system programmer working on the development of a multi-layer secure Wan project. He is responsible for such a system, which is composed of three VAX and three sun machines on the west coast and connected with the system with similar configuration on the east coast through an encrypted 1200 baud serial line, because Larry’s main work is support (he is not a programmer of the project, but a system expert), So he has the opportunity to use his three advantages (laziness, impatience, and arrogance) to develop and improve all useful tools – such as RN, patch, and warp. (Note: it is at this time that Larry is classified into the category of “computer animal”, which is based on the unstoppable “another feature” of those people Because this behavior has almost become a biological necessity. After all, if life is too complicated, wouldn’t the program? Especially for programs like RN, it should really be treated as an advanced artificial intelligence project, because they can read the news for you. Of course, some people are already saying that the patch program is too complex.)

One day, Larry just tore RN into pieces and put it in his directory one by one. The chief administrator ran in and said, “Larry, we need a management configuration to control all six vaxs and six suns. We want it in a month. You can make one!”

Therefore, Larry, who never evades work, began to ask himself what is the best way to build a CM system for two coasts. It must not be written from scratch, and you can also consult the problem reports, approval and control of the two coasts. The answer he came up with was only one word: b-news. (Note: This is the second implementation of Usenet transmission software.)

Larry started installing news software on these machines and added two control commands: an “append” command to add content to existing articles, and a “synchronize” command to keep the number of articles on the two shores the same. Cm can be done with RCS (version control system), while approval and control can be done with news and RN. So far, very good.

Then the chief administrator asked him to generate a report. News is maintained in an independent file in the core machine, which has many cross references between files. Larry’s first reaction was “use awk.” Unfortunately, awk at that time could not open and close multiple files based on the information in the file. Larry didn’t want to write a special purpose tool, and the result was a new language. At first, this new language was not called Perl. Larry exchanged a lot of names with his colleagues, relatives and friends (Dan faigin, who wrote this history, and mark Biggar, his wife and brother, helped a lot in the initial design stage). In fact, Larry considered and abandoned all three or four letter words in the dictionary. The earliest name was Gloria, named after his baby (and wife), but he soon found that it would cause too much family chaos.

Then the name became “Pearl”, and finally it became our current “Perl”. In part, Larry saw the introduction of another language called pearl, but the main reason was that he was too lazy to always hit five keys. Of course, Perl can be used as a four letter word. (however, you will notice that there are remnants of the previous acronym: “Practical Extraction and report language”.)

The earliest Perl did not have as many features as Perl today. At that time, there were pattern matching and file handles, scalars and formatting, but there were few functions, no related arrays, and only a poorly implemented regular expression (borrowed from RN). There are only 15 manual pages. But Perl was faster than sed and awk and began to be used in other applications of the project.

But other places are starting to need Larry again. One day another big manager came and said, “Larry, support R & D.” And Larry said, okay. He took Perl with him and soon found that it gradually became a good tool for system management. He borrowed Henry Spencer’s beautiful regular expression package and made it more manly (but Henry may not be willing to consider these features at dinner.) Then Larry added most of the features he wanted, as well as some of the features others wanted. Then it publishes Perl to the network. (Note: what’s more surprising is that he continued to release new Perl after working at the Jet Propulsion Laboratory (JPL), then netlabs and Seagate. Now, others do most of the work, and Larry pretends to be O’Reilly & Associates (a small company that prints brochures about computers and related things) The rest is history. (Note: these things are an annotation of history. When he started working in Perl, Larry had broken down RN into pieces and was ready to do a comprehensive rewrite. However, since he started working in Perl, Larry didn’t touch RN again. It was still a fragment. Sometimes Larry said he wanted to rewrite RN in Perl, but he never took it seriously.)

Then things went like this: Perl 1.0 was released on December 18, 1987; Some people still take Perl’s birthday very seriously. Perl 2.0 was released in June 1988, and Randal Schwartz started “another Perl hacker”autographThe legend of. In 1989, Tom Christiansen presented the first public Perl tutorial in USENIX, Baltimore. Beginning with Perl 3.0 in October 1989, the language was first released and distributed in GNU Public Copyright (GPL).

In March 1990, Larry wrote his first Perl poem (see the next section). Then he and Randal wrote the first edition of the book, the pink camel; The book was published in early 1991. Then Perl 4.0 was released immediately; In addition to GPL, it also includes artistic license.

The much anticipated Perl 5 was released in October 1994. This is a completely rewritten version of Perl, which includes objects and modules. The advent of Perl 5 is even mentioned in the Economist magazine. By 1995, cpan was officially introduced to the Perl community. In 1996, Jon orwan began publishing the Perl journal. After a long period of speculation, the second edition of the book, the blue camel, was published at the end of that year. The first O’Reilly Perl Conference (TPC) was held in San Jose, California, in the summer of 1997. Now, major times happen almost every day, so for other parts of history, please check the Perl chronology on cpast (Comprehensive Perl Arcana society tapestry (history. Perl. ORG)).

2. Perl Poetry
The imitation of the poem in the assistant box was posted on Usenet on April 1, 1990. We put it here without comment, just to show how disgusting the metaphor of a typical programming language is. Probably for all things of literary value. Larry felt a lot easier after the “black Perl” originally written for Perl 3 could not be analyzed by Perl 5.

However, Larry’s own anthology was fortunately overshadowed by the light of Sharon Hopkins, the queen of Perl poetry. She has written quite a lot of Perl poetry, as well as some articles on Perl poetry she presented at the 1992 Usenet winter technology conference, entitled “camels and needs: computer poetry meets the Perl programming language”. (this article can be found in misc / poetry.ps of CAPN.) In addition to being the most prolific Perl poet, Sharon is also the author of the following poem, which is the most widely published one and has been published in economist and guardian magazines:

 

Copy codeThe code is as follows:


#!/usr/bin/perl
APPEAL:
listen (please, please);
open yourself, wide;
join (you, me),
connect (us,together),
tell me.
do something if distressed;
@dawn, dance;
@evening, sing;
read (books,$poems,stories) until peaceful;
study if able;
write me if-you-please;
sort your feelings, reset goals, seek (friends, family, anyone);
do*not*die (like this)
if sin abounds;
keys (hidden), open (locks, doors), tell secrets;
do not, I-beg-you, close them, yet.
accept (yourself, changes),
bind (grief, despair);
require truth, goodness if-you-will, each moment;
select (always), length(of-days)
# listen (a perl poem)
# Sharon Hopkins
# rev. June 19, 1995
Perl Poetry
Article 970 of comp.lang.perl:
Path: jpl-devvax!pl-dexxav!lwall
From: [email protected](Larry Wall)
Newsgroups: news.groups,rec.arts.poems,comp.lang.perl
Subject: CALL FOR DISCUSSION: comp.lang.perl.poems
Message-ID:
Date: 1 Apr 90 00:00:00 GMT
Reply-To: [email protected](Larry Wall)
Organization: Jet Prepulsion Laboratory, Pasadena, CA
Lines: 61

 

It has come to my attention that there is a crying need for a place for people to express both their emotional and technical natures simultaneously. Several people have sent me some items which don’t fit into any
newsgroup. Perhaps it’s because I recently posted to both comp.lang.perl and to rec.arts.poems, but people seem to be writing poems in Perl, and they’re asking me where they should post them. Here is a sampling:
From a graduate student (in finals week), the following haiku:

study, write, study,
do review (each word) if time.
close book. sleep? what’s that?
And someone writing from Fort Lauderdale writes:
sleep, close together,
sort of sin each spring & wait;
50% die
A person who wishes to remain anonymous wrote the following example of “Black Perl”.  (The Pearl poet would have been shocked, no doubt.)

BEFOREHAND: close door, each window & exit;  wait until time.
open spellbook, study, read (scan, select, tell us);
write it, print the hex while each watches,
reverse its length, write again;
kill spiders, pop them, chop, split, kill them.
unlink arms, shift, wait & listen (listening, wait),
sort the flock (then, warn the “goats” & kill the “sheep”);
kill them, dump qualms, shift moralities,
values aside, each one;
die sheep! die to reverse the system
you accept (reject, respect);
next step,
kill the next sacrifice, each sacrifice,
wait, redo ritual until “all the spirits are pleased”;
do it (“as they say”).
do it(*everyone***must***participate***in***forbidden**s*e*x*).
return last victim; package body;
exit crypt (time, times & “half a time”) & close it,
select (quickly) & warn your next victim;
AFTERWORDS: tell nobody.
wait, wait until time;
wait until next year, next decade;
sleep, sleep, die yourself,
die at last

I tried that, and it actually parses in Perl.  It doesn’t appear to do anything useful, however.  I think I’m glad, actually… I hereby propose the creation of comp.lang.perl.poems as a place for such items, so we don’t clutter the perl or poems newsgroups with things that may be of interest to neither.  Or, alternately, we should create rec.arts.poems.perl for items such as those above which merely parse, and don’t do anything useful.  (There is precedent in rec.arts.poems, after all.)  Then also create comp.lang.perl.poems for poems that actually do something, such as this haiku of my own:

print STDOUT q
Just another Perl hacker,
unless $spring

Larry Wall            [email protected]

 

The old Perl never stopped innovating. On July 18, Perl 5.8 0 published.
5.8. The highlights of 0 are:
-Better Unicode support:
Since version 5.6, Unicode support has been significantly updated at all levels:
-Unicode 3.2.0 support Version 0 (Perl 5.6.1 supports version 3.0.1)
-Provide a more general and smooth Unicode environment at the language and internal levels
-Regular expressions can work with Unicode
-Provide encode module to support existing coding methods (including various Chinese / Japanese / Korean systems)

-Multithreaded execution mode:
Interpreter threads is a new multi-threaded execution mode. We strongly recommend that you use it to replace the old 5.005 multithreading mode The main difference between the two is that the information to be shared must be clearly announced under ithreads

-New I / O mode:
The new perlio mode also provides source level cross platform stdio implementation and richer output / input control architecture

-More accurate values:
Previous versions of Perl relied on string / numeric conversion functions on your system; This often leads to cross platform obstacles and wrong calculation results

-64 bit support:
The current 64 bit support is mature – if your system supports 64 bit integers or address spaces, you can specify these functions at compile time

-Safe signal processing:
In previous versions, Perl might break the internal state of the interpreter when receiving signals

-A large number of new modules:
Digest::MD5, File::Temp, Filter::Simple, libnet, List::Util,Memoize, MIME::Base64, Scalar::Util, Storable, Switch,Test::More, Test::Simple, Text::Balanced, Tie::File, …

-Thorough compatibility testing:
Perl now has six times the test suite of version 5.6, and is installed and tested on various platforms every day

[compatibility]
-Binary file incompatibility:
Mainly due to the import of perlio, there is no “binary compatibility” between Perl 5.8 and previous Perl versions You may need to compile each XS extension module again

-AIX dynamic load:
In order to be more compatible with other programs on AIX system, Perl enables system dynamic loading on AIX system instead of the previous simulation mode

-Disable Perl malloc memory configuration on 64 bit platforms:
Perl’s malloc function seems to have many problems on 64 bit addressed machines Therefore, we now use the system’s native malloc function by default

-The hash order has changed again:
Perl’s internal hash function has been changed to a better version, but this is not a problem as long as your source code does not depend on a specific hash key order

-Change the attribute of my to be processed at the execution stage:
The properties of the my () variable are currently handled at run time instead of compile time

– REF(…) Replaced scalar (…):
In order to comply with the result of ref (), the reference to the reference is changed to “ref (…)” in the string express.

-The updated Unicode processing mode greatly reduces the need to use “use utf8”: in Perl version 5.6, whether the data is regarded as Unicode depends on whether its operation is within the valid range of “use utf8” and compilation commands; Perl 5.8 now links “Unicode properties” directly to data Therefore, at present, “use utf8” is only required when UTF-8 literal is used in the program code (in the absence of “use utf8”, in order to maintain compatibility with the existing command script, the literal value is still treated as a byte.)

-VMS: socket extension module is dynamic, and IEEE floating point number is preset for alpha
-The socket extension module is dynamically loaded on the VMS platform; This may cause problems on very old VMS
-OpenVMS Alpha currently uses IEEE floating point format by default See readme for reasons and details vms.

[word change]
-The “IO discipline” in the third edition of programming Perl (Perl programming) is now called “IO layer”

[not recommended]
– dump():
The function of the dump instruction is currently regarded as obsolete

-5.005 multithreading mode is no longer recommended
Please use the new interpreter multithreading mode

-Virtual hash (pseudohash):
The user – level virtual hash syntax will be removed and replaced with a simpler interface In addition, the internal implementation must be changed because it slows down the access speed of general hash

-Contaminated data in “exec” and “system” parameters:
At present, this will trigger a warning message, but it will become a fatal error in future versions

– tr///C, tr///U:
These two operation interfaces are an accident; Please use pack (“C0”,…) And pack (“U0”,…)

[known issues]
-Amigaos cannot install Perl 5.8 0
-Compiler Suite: bit code compilation and native code compilation are still problematic
-Lvalue lvalue function is still regarded as experimental
-The result of the interaction between local () and tie () is not clearly defined
-Tied or magic arrays and hashes are not automatically generated
-Self – binding arrays and hashes are currently disabled

Again, please read pod / perldelta Pod, install, and readme Platform.