[Reposted] About Perl - Perl Learning Handbook

xiaoxiao2021-03-06  39

http://perl.hcchien.org/ch01.html

1. About Perl

When you open this book, you have entered a fantasy world. Perl is indeed a very attractive programming, and the reason why this fascinating thing is not only his function, it is the way he writes, or it becomes a program of writing. Even if you are just a program designer who buried in a program every day, no longer let your life are monotonous, at least you can try to change more in the program code. And many PERL's programming designers have been doing this, which is also the concept of Perl - "There is more than one to do it".

Often encounter someone asking me: "What can I do?", But later I slowly discovered that the answer to this question is very diverse. Because almost someone in different areas is using Perl, they will have a big difference to give you the answer. Some people will feel that Perl is very convenient to use in biological information. Some people also have a wide range of dealing with corpus. Of course, there are still many people who take Perl as a system-managed tool, which is a good helper for processing system logs.

1.1 Perl history

Perl created by Larry Wall first appeared in the USEN's news group Comp.Source in 1987. From the 1.0 version released at the time, it was almost a year to update the update of a large version of the year, which in 1989, PERL has already version 3.0. In 1991, the Perl development team developed a quite key version 4.0. Because with the release of version 4.0, Perl published a new copyright statement, which is Perl Artistic License. Perl4 has been separated from Perl5 for three years, gradually, Perl architecture has become increasingly stable. It has been recently, and Perl released the new Perl version 5.8 and the development of a new generation of versions.

1.2 perl concept

Perl is very easy to use, or we should say that he is a convenient programming, you can write a PERL program, just like you play a directive in the command column (Note). Because Perl's birth is almost letting the user can write a code in a better way, it is not necessary to consider a lot of details like writing C.

In addition, Perl's stickiness is very strong (note), you can connect different things easily with Perl. And you can use Perl to solve most of your questions, although you don't want to do this, but this doesn't mean that Perl can't do it.

1.3 features

Many people's impression of Perl is a programming of CGI (Note 3), or intuitive thinking Perl just tools for processing text. But just like what we said, Perl can almost do most of the work you want to reach. However, it is undeniable that formal representation is clearly a part of PERL is enough, which is one of the reasons why Perl is taken to use as text processing.

And Perl is really helpful for you to quickly complete some of the work. Even in the Unix-Like environment, you can also use Perl-based shell to use Perl as an instruction. And don't have to be in many way languages, you must prepare a bunch of things before you have not officially working, including your variable definition, your data structure, etc. Therefore, many of many UNIX-Like systems also like to take Perl to perform system management. After all, no one wants to deal with a mail documentation, you have to spend a bunch of time. How to make a lot of things in the documentation into a suitable data structure.

1.4 Environment using Perl

Although most UNIX-Like system administrators choose Perl to help them manage their servo, this is definitely not to indicate that Perl can only be executed on these systems. Conversely, Perl can be performed on the vast majority of operating systems. The current Perl on Windows is dominated by the direct translator provided by Active Perl (http://www.activeperl.com). Perl's use is slightly different under different job systems, and this book is in Unix-Like as an execution environment. 1.5 Start using Perl

Before you start using Perl, you must first determine if you have installed Perl. In many UNIX-LIKE operating systems, all presets will be installed, you can also perform the following instructions to determine the Perl version in the current system.

[hcchien @ apple]% perl -V

THIS IS Perl, V5.8.2 Built for Darwin-2Level

Copyright 1987-2003, Larry Wall

Perl May Be copied only Under the Terms of Either the artistic license or the

GNU General Public License, Which May Be found in The Perl 5 Source Kit.

Complete Documentation for Perl, Including Faq Lists, Should Be Found ON

This system using `man perl 'or` perldoc perl'. if you have access to the

Internet, Point Your Browser At http://www.perl.com/, The Perl Home Page.

We see some part of the version, which is used here is version of Perl 5.8.2, and then have the name of the writer Larry Wall, which is copyrighted. Next is the copyright instructions of Perl. In addition, you should pay attention to `Perldoc Perl ': You can see the files included in Perl directly under your terminal, and the content is very detailed.

Here, we recommend using the version of Perl 5.8, if your version is too old, or there is no Perl in the system, you can download from http://www.perl.com/, and install Perl.

If your system already has Perl and working properly, then you can start using your Perl. You can try to use all schedule languages ​​as the beginning of using Perl:

[hcchien @ apple]% perl -e 'print "Hello World! / N"'

Hello World!

But in Windows, because the command column can't use single quotes, so you have to write this:

[hcchien @ apple]% perl -e "print /" Hello World / N / ""

Hello World!

1.6 Your first Perl program

In fact, you have just had your first Perl program. Of course, you can not admit that it is a Perl program. But let us really write a process. If you are accustomed to using many integrated program development tools, you probably want to know what tool to install to write Perl. But you may have to be disappointed, because all of us is just a text editor. You can choose VI (Vim), Joe, or any editor you habits, you can use Notepad on Windows, or download UltraEdit (http://www.ultraedit.com/). But please do not use such a paper processing tool similar to Word, because you just make things more complicated. Of course, even if you are on Windows, you can also choose VIM or Emacs These text editor in UNIX World Get highly evaluated, and they are free software. Now we can lay the first process:

#! / usr / bin / perl

Print "Hello WORLD / N";

I believe that everyone will quickly finish this process. Don't tell what you said in the end (although you should understand), let's take him first!

[hcchien @ apple]% perl ch1.pl

Hello World

It's great, the result is like the look that we do with the command column. But at least we know, just use Perl to perform the program we wrote, of course, you can have a simpler way. You can make your files become executable, under UNIX, you only need to use CHMOD to reach this. Of course, we assume that you can operate your system and at least understand file permissions. After modifying the permissions, you only need to fight in the archive:

[hcchien @ apple]% ./ch1.pl

Hello World

So what is the meaning of the first line? In fact, this is a UNIX system that indicates how this approach is implemented. Here, we want to use the "/ usr / bin / perl" program. So please rewrite in accordance with the actual situation in your system. Otherwise, when you are executing, you are likely to see the error message such as "Command Not Found".

However, before you really start writing Perl, we have to remind a few things, these things are important for you to start writing Perl.

1. Perl's narrative sentence is separated by a semicolon (;), so as long as your narrative sentence has not shown a semicolon, Perl will not treat him as a complete end, unless you are in one The last sentence of the block. We can find such examples in Perldoc;

Print

"Hello WORLD / N"

;

And such a way of writing is nothing different from Perl, but it is clear that people who need to maintain your program will not be particularly pleased. The time-time gap can indeed increase the readability of the program, but remember not to abuse, causing the blame to suffer.

2. Perl is a well-decorated annotation with a wellhead number (#), that is, as long as the wellbin is started, the content before the end of the narrative sentence will be annotated, and the Perl will not try to perform him or compile him. For some programs that are accustomed to C programmation, (/ * ... * /) can be used to make a program is indeed quite convenient. Perl does not have a formal definition method to make an annotation of the entire block, but it can take advantage of the same purpose using other ways. For example, use POD (Plain-Old Documentation Format, concise file format):

#! / usr / bin / perl

Print "Hello World / N"; = HEAD1

Here is actually annotation, so it is also very convenient.

Mainly, you can put a lot of lines in turn.

= CUT

If you want to find out other possible alternatives, you can directly see the Perlfaq file, and the method is to perform Perldoc Perlfaq (Note 4).

Next, we must really enter the Perl environment.

exercise:

1. Try to find why the Perl version on your computer.

2. Use Perldoc Perl to find all perl file content

3. Use Perl to write the first program, print your name

Note 1: In fact, Perl has a so-called single line mode, you only need to perform Perl's narrative sentences in the command column.

Note: Some people also joked Perl as "glue programming language".

Note 3: It is the so-called "Common Gateway Interface", a dynamic website design interface.

Note 4: There are many very useful files in Perldoc, you can consider trying to see Perldoc Perldoc.

转载请注明原文地址:https://www.9cbs.com/read-61528.html

New Post(0)