Preface
According to the Perl Language Reference Manual, Perl isPractical Extraction and Report Language(Practical report extraction LanguageIt is designed by Larry Wall and constantly updated and maintained for programming in UNIX environments.
- Perl has the power and flexibility of advanced languages (such as C. In fact, you will see that many of its features are borrowed from the C language.
- Like a scripting language, Perl does not require compilers and connectors to run code. All you need to do is write a program and tell Perl to run it. This means Perl is ideal for rapid solutions to small programming problems and for creating prototypes for large events to test potential solutions.
- Perl provides all the functions of the scripting language (such as SED and awk) and has many features that they do not have. Perl also supports translator from sed to Perl and from AWD to Perl.
In short, Perl is as powerful as C and as convenient as awk, sed, and other script Description Languages
Body
Perl is exposed because Perl is powerful in text processing. Baidu later found that Perl is basically used for text operations, such as replacing a specific string in a file,
Perl-pi-E's/originaltextstring/replacementstring/G' filename
The meaning of the parameter-pi-E is not very clear. The end G indicates that there is a match in the replacement document,
This statement is directly executed on the terminal as a shell statement or written in a shell script,
The following is an example to demonstrate how,
1. Create a new text for testing and enter some content
VI testperlreplace
2. After the file is created, check what I have written:
Cat testperlreplace
-----------------------------------------------
Test Ni da ye
Nidayede testtest
----------------------------------------------
3. replace all the test values with hello,
Perl-pi-E's/test/Hello/G' testperlreplace
4. Now the text content has changed,
Cat testperlreplace
---------------------------------------------
Hello Ni da ye
Nidayede hellohello
---------------------------------------------
Supplement
About Perl after the-P,-I,-E on behalf of the meaning of the table, Google has a foreigner to answer this question, I do not know the correctness of how: http://www.linuxquestions.org/questions/programming-9/perl-replace-text-in-file-476382/
- -P tells Perl to traverse the file name parameters added later, which is similar to the Code in sed.
While (<> ){
... # Your program goes here
} Continue {
Print or die "-P destination: $! \ N ";
}
The above example is just a separate file. In the example, it should be able to match multiple names or even;
- -I is generally used to perform backup operations when reading files.
- -E tells Perl to keep up with the Perl statement.
-P and-I can be combined-Pi and-p-e can be combined, but-I and-E cannot be combined to write-ie, the following statement replaces the test string with hello in all files prefixed with testperlreplace.
Perl-pi-E's/test/Hello/G' testperlreplace *