Perl is the expert level of the system administrator's preferred scripting language, but its role is far more than that. As a design for file and text processing language, in addition to a variety of other uses, it is also extremely suitable for UNIX system Management, Web programming, and database programming.
As one of the most easy programming language, it is very easy to use, can be as simple task to write efficient code, so Perl it is easy to attract new users and become they complete their tasks one of the important and commonly used tools. The official start of the discussion of Perl programming before, there are some things you need to know, they can let you write code and the Perl experts the time to make the programming work easier.
Perl sometimes is considered to be practical extraction and report language(Practical Extraction and Report Language), because it in the extract the data and use the data to create reports on a very easy to use. It is also funny to called the metamorphosis of e-waste list program(Pathologically Eclectic Rubbish Lister), because you use it after a period of time will experience out of this. Which two statements are“official”, are also correct, but this language is not PERL. Perl the name of the appears to be than these two sayings of the invention is to be early, and the fact this language in spelling is simply not an acronym. Speaking in the language of the time, you want to call it Perl, because it is used to run it a command of spelling it. In and Perl hackers dialogue, recognize don't know anything a novice the easiest way is to call it PERL.
The Perl language and the community one of the main motto is TIMTOWTDI, pronounced a method is“Tim Toady”is. This really is an acronym, which means“complete in more than one way(There Is More Than One Way To Do It)”on. Perl's hierarchy is really a lot, this is what you need to remember important content. Although the completion of a certain method than to accomplish the same thing the other method is better, but you can be sure of is that you can use Perl to do many things, complete ways than one.
Warnings and the strict pragma is a Perl hack arms library is used to debug code is an important weapon. A warning will not prevent the program from being executed, but for how to fix the code to provide useful information.
If you do not use a strict style of programming, such as defining the scope of the variable, the strict pragma will really prevent the code from being executed. Sometimes, a program may not use the strict pragma would be better, but if you are just beginning to use Perl, then you need quite a long time to be able to realize that this is the case, at that time although use it.
In a standard UNIX system, in the command line to start the warnings and strict pragma Perl script looks like the following:
The warning can also be used a statement to start, like this:
In Perl, a pragma is a preprocessor Directive. In other words, it is one in the code is compiled before execution to the compiler instructions. Pragma changed the compiler to analyze the code.
Through the program's command line the-T parameter, you can explicitly start the error checking. This is a used to check a program where all input to prevent the“wrong”data security means, if a malicious user tries to hack run you Code of system security, which helps ensure that the received data does not allow for arbitrary code execution. This in you use Perl / the CGI script processing on the Web page HTML data is particularly important. It can be used with the-w parameter is used together, that is-wT.
Through the static scope, you can use the my()operator to create variables. Simply put, this means that the variable scope is limited to the current context; if you're in the subroutine, use the my()declares a variable, then this variable can only exist in the subroutine. Static scope the value is separated from the module code The various parts of something.
For example, if you're using a Perl module or library, but don't exactly know what code is what, then use the static variable will be able to help prevent accidentally put the new value given the need to subsequently remain a constant variable. In the use of Perl to write the static scope of variables when, in your variable using the static range is to have its effect. For example, from other languages go to the Perl of people, you may need to know the static range of variables, it was also said that these variables are“private variables”.
The Perl program should be in their name with a proper extension. A lot of poor quality Perl description simply put. pl used for all file extensions, such as the Perl script named foo. pl. Technically, the. the pl extension should be used for Perl libraries, rather than executable Perl program. For executable files, you should be using. plx, or if youroperating systemallow, simply do not use extension can be. Perl module should be used. pm file extension. In the Perl script file name Use only letters, numeric characters, and underscores with a letter(or underscore)as a file of the first character(which with the variable names the first character of the like)are considered very good practice.
The comprehensive Perl archive network Comprehensive Perl Archive Network, CPAN has become a looking for a free, reusable code rich resources. In CPAN, you can find a lot of Perl modules, which can be used to enhance program function and reduce the write code time. Use the CPAN depends on youroperating system, and Perl parsers to implement, but you can use a Web browser to access the CPAN。 Perl implementations are generally provided with at least one command-line tool used to install from CPAN Perl module.
Perldoc form for the Perl online documentation a huge number and rich in content. The Perldoc installed on your system, you can use it to get any on standard Perl functions, installed modules, variables, as well as some other things in the document-even on Perldoc's own documentation! This is like Is in your hand Put a set of the most complete programming reference books, free, may search, because it is the electronic version.
In some systems, the Perldoc by default it will along with Perl are installed, while in some other system, you need your do it yourself installation. If the installation Perldoc when run into a problem, you can access the Perldoc Online website. You have to make sure that you know how to use Perldoc, since it can make you more effective in an unexpected way for you to become a Perl hacker.
You should always use subroutines, modules and libraries. This helps to more quickly write code, and help to prevent you need in multiple programs use the same function, or in a program where you need to repeatedly use the same function in the case the code can become unmanageable. Do this by using subroutines, modules and libraries to put the code block with the other of the source separately to achieve. In most cases, you better use the already existing design, without re-from sketch start to invent the wheel. In addition, when the re-used from a subroutine, module, or library code, you more or less need the code for some improvements.
In Perl, the“subroutine（subroutine”this term is roughly equivalent to the C language in the“function function” is.
1 0. Regular expressions are your friend
Perl the regular expression syntax can help to make your code look is layman's work, which leads to sometimes Perl programming for beginners avoid using regexen to. This really is a big mistake. Regular expressions as the Perl programming language adds a lot of capacity, it is often possible to make a program with three lines of code to complete the other language with the fifty line to complete the task. A regular expression is composed of some abbreviations consisting of the expression, for matching string patterns, these strings can be used to find and manipulate a large string, small string. So Perl hackers it is necessary to learn and master regex syntax.
Using the regular expressions of Perl hackers and other programmers are often called“regexen”or“regexes”in the singular form is“regex”. the“regex”another version is“regexp”, but I don't know why someone would add this one so it becomes more difficult to phonics of the letters.
Once you digest this article lists these things, you're ready to really start learning Perl and how to use it to programming. There are some for beginners also to experts of excellent resources, including the learning Perl on--a very good introductory article, the PerlMonks community, with tutorials and discussions, and Ovid's CGI course-Perl / or CGI Web programming.