PERL CGI introduction and instruction demonstration This article comes from: http: //www.01-world.com Author: Caiqi Yu, even Han Zhen, Zhang Zhiqiang (2001-08-22 12:00:00) taken from Caiqi Yu, even Zhen Han, Zhang Zhiqiang's "CGI Programming Guide" Chapter 6 is to respect the author copyright, only part of the election, to introduce it, recommend you to buy the original book!
6.1 Perl Language Introduction 6.2 How to Use Perl to write a program 6.3 Perl syntax introduction 6.3.1 Perl language Variables 1, the use of the Purlar Variables, the use of arrays, the use of arrays, associated arrays usage
6.3.2 Perl Commonly used in the design of CGI program #printprintfchopsplitkeysvalueSreverSortLengthsubstrindexpushpopunshiftshiftjoingRepHexrandLocalTimedieopenClosePackReadexit
6.3.3 Perl Language Operation Symbol Character 1. Assignment Operator II, Arithmetic Operator II, Numeric Values Relational Operator Five, StringValues Relational Operator V. Logical (Logical) ) Operator six, other common operators
Block operator condition operator
Seven, common file data (File Test) operator
6.3.4 Process Control of Perl Language, Selective Process Control
If if unless, if unless
Second, circulatory process control
While is do while is ..untile until .. is only DO Until until .. only for cycle statement Foreach loop statement Last Exit cycle statement next to the loop Next statement
6.3.5 Perl Language Text Processing Mode 1
/ pattern / text operation = ~ matching operator! ~ non-equivalent operator TR conversion function S replaces function
6.4 Introduction to Perl for Win32
6.1 Introduction to Perl Language
Perl (Practical Extraction and report "is called a text analysis report language. Is Laracle Wall (Larry
Wall) established language. The philosophy when he is designing Perl is to be a first priority, that is, language is easy to use, efficient, and complete. The Perl language contains C, C , Shell
Script, sed, awk's grammar, its original purpose is to replace Unix original SED / AWK and Script combination, used to make information, generate a toolbar for reporting
Say. With the improvement of the version, the function is getting stronger, and the current function is exceeded as the imagination of the original design, almost anything can be done, and it has become a standard tool for each workstation.
. Because it has strong processing capabilities on strings and data profiling, especially using associated arrays to analyze input data strings, it can be said to be a powerful language! This interpretation of Perl is in China Users may be very strange, maybe there may be no heard, why do you want to write CGI applications with Perl? Because Perl has a strong word
String processing capabilities, software in foreign countries that process databases can communicate with Perl. In the Perl5.0 version, the object-oriented usage is added, increasing the processing capability of the string, which can be
The entire file is used as a string to handle, the size of the memory is not subject to the size of the memory, and the DBM database format can be processed can handle binary data, etc.
More importantly, Perl can also be used in operating systems such as UNIX, WindowsNT, Windows95, DOS, Linux, FreeBSD, OS2, Macitosh. You can also use Perl and one
Some database software communicate, some of the powerful CGI applications in foreign countries is almost all used by Perl language! Readers see that this powerful language Perl must be very
I am very wrong! This is very wrong. Perl is very easy to get started. Its grammar and C language are very close. For those who are familiar with C language, Perl is easy to get started, as long as there is a little C language The foundation, plus a few hours of learning time, you can easily write a simple CGI app with Perl language. As for those who don't have C language, just spend more time to learn
It is also possible to use the Perl language quickly to write the CGI application! At that time, you will find that the original Perl is so close-up, and the CGI app written is so simple and powerful.
The author believes that the Perl language must be the role of the best male WS95, WINDOWSNT These 32-bit operating systems use Peri to write CGI applications. Do you know how powerful you want to know how powerful? 6.2 How to use Perl to write a program If Perl is installed in the system, we can use "Which Perl" or "Which Perl5" instruction to learn which directory is located in the system. % Which Perl / USR / BIN / Perl or% Which Perl5 / USR / LocaiaIn / Per15 can be used to write the program code. If you want to know the Perl version, you can use "Perl-V" or "Perl5-V", this instruction to learn the version of Perl. Current perl The latest version is a 5.x version, and the syntax instructions described below can be executed in Perl4 and Perl5 versions. If you can't find this software on your workstation, you can want to Seeking this very practical software. Next, you can edit the program code using the system's instrument editor (for example: vi, joe, pico, etc.), and must add the first line of the program code, start with the #! / Path / per1 program Declared. For example, use "Which Perl "This instruction is to know the / usr / bin / perl this path file name, so when the write range, be sure to write on the first line of the program code # / usr / bin / perl The system knows which system knows which execute file to perform this write code code, next to this file, can be written in this file. This is Perl language (explanation) Formulations) and C Language (Compilation) The biggest difference in program writing. In the C language, you can perform the original program code and make a execution file can be executed in the system, and the Perl language is in the original The first line of the pendant code uses #! Add the absolute path and file name of Perl to tell the system to use Perl interpreter to explain these original program code. After writing the program code, be sure to change the file attribute to executable, for example, can change the file attribute to everyone (CHMOD 711 FileName). However, usually we are When writing CGI applications, in order to avoid other errors, it is best to change the file attribute of the CGI application to everyone, you can have the right to read, execute (CHMOD 755) FileName). And # This symbol is a representative annotation in the Perl language program code. Perl does not deal with the narrative of this line, so in the following examples, if this symbol is displayed, it is a pen For the description of the program code, you will explain to the reader first. 6.3 Perl Syntax Introduction In order to let everyone know more about the Perl language, before introducing the CGI application, first introduce the basic syntax of Perl, the author first introduces PER1 language to introduce Per1 in this chapter. The most common syntax function in the CGI program design, I hope everyone can understand the Perl language after reading this chapter. As long as these basic syntax is familiar with, Use Perl to write CGI applications with Perl. 6.3.1 Variables in Perl Language The variable of Perl basically has three types of pure quantity variables, array, associated arrays, and the following is how these variables: I. Usage of Schle Variables In Perl language, the use of variables in the Perl language must be announced in advance. When using the pure amount variable, add $ this symbol, pay attention to if the specified Pure volume variable is one If the string is, it is necessary to add "" this double quotes. If it is a value, you don't have to add "" "this symbol. Here are some examples: $ strl = www "; # Specify WWW string to $ Strl this pure variable; $ str2 =" cgi "; # assigns this string of CGI to $ STR2 pure variable; $ STR3 = Strl. $ str2; #. This is to connect two strings, so $ str3 = "wwwc20"; $ int = 5; # 将 5 This figure is specified to $ int this pure variable; $ INT = 3 2; # = 3; $ int = 3 * 2; # = 6; $ int = l0; $ int ; # = 10 l = 11; $ INT = L0, $ INT = 5; # = 10 5 = 15; II. The use of arrays is using an array to add @ 这个,, here is some examples: @namel = ("Tom", "Mary"); # # t "," Mary ", specified two strings to array @ name1 @ name2 = @ name1; # @ Name2 = (" Tom "," Mary ") @PAME3 = (" john ", @ name1); # this time (Name3 = (" John "," Tom "," Mary ") ($ one, @ name4) = @ Name3; # This time $ One = "john", and @ Name4 = ("Tom" '"Mary") @ Namel = 0; # This time @ Name1 is an empty number @ Int = (1, 3, 5, 7, 9); $ x @ @T; # Specify an array to a pure amount variable, will return a number of components #, so at this time, at this time, $ x = 5 $ x = # int; # $ # This variable will return to the array last Index # of an element, so $ x = 4 ($ x) = @ int; # $ x is equal to the value of the first element of array @int, # So this time $ x = 1 $ b = $ int [0 ]; # $ B is equal to the first element of array @int, so $ b = 1 $ c = @ int [0]; # $ c is also equal to the first element of array @int, so # $ c = 1 Therefore, the value in the array is to have the above two methods $ int [0] = 2; # Specify the 2 value to the first element of the array @int # @ Int = (2, 3, 5, 7) 9); $ int [0, 1] = [1, 3]; # Assign 1 to the first element of the array @int, and the 3 fingertips # set the second element of the array @int, so # @ INT = (1, 3, 5, 7, 9); @int [0,1] = @ int [1,0]; # # 将 的 的 的 元 # = (3, 1, 5, 7, 9) ($ int [0], $ int [1]) # is also swaping the first two elements of array @int = ($ INT [L], $ Int [0] ); # @ INT = (1, 3, 5, 7, 9); @ data = @ Int [0, L]; # @ Date = (1, 3); $ int [5] = 11 ; # Assign 11 this value to the sixth in the array @int Element # At this time @ INT = (1, 3, 5, 7, 9, 11) Third, the Usage of Associative Arrays is also one of an array, which is composed of different pure amount variables. However, different parts of the array is that the elements in the associated array are composed of pairs of Key-Value, that is, every key has a Value, which is a unique syntax in Perl language. Therefore, initiators may be more strange to associated arrays, and the author will be more details here. Fine description. If the syntax application of the associated array can be found in the CGI program design, it will find that the associated array is a good syntax. When using the associated array, add% this symbol, and the format of the associated array is as follows:% array = (Keyl, Value1, key2, value2, key3, value3 ...); each key has a corresponding Value. l. In the associated array, change a pair of data: $ array {key} = value; plus a pair of key-value in the associated array array, first add $ this symbol before the associated array name, and Key The name is between the {} symbol, and finally specifies the value value corresponding to the key. If there is already this key in this associated array, you will change the value corresponding to this Key. 2. Remove the value: $ get = $ array {key} in the associated array: $ get = $ array {key}; take out the value corresponding to the key in the associated array array, first add $ this before the associated array name The symbol, and the name of the key is between the {} symbols, and the value corresponding to the key will be taken out and specified to the $ GET variable. 3. Delete a pair of data in an associated array: DELETE $ array {key}; delete is the function provided by Perl, the function is to delete a key in the associated array and the value corresponding to this key. How to use is after the DELETE function, then specify the number of associations The name of the key to delete the key. The following is some examples of the method of associated array usage:% name =
6.3.2 Perl commonly used in CGI program design -------------------------------------------------- ------------------------------ instructions: # 说明:: 注解 符 r Remark Declaration example: # This program is a demonstration annotation -------------------------------------------------- ------------------------------ Command: Print Syntax 1: Print FileHandle List Description: This FileHandle can see it as I A bridge between INPUT / O (OUTPUT) can utilize FileHandle to make actions written in data read. STDIN is the representative Input data, such as from the computer's keyboard input, stdout is the output data representing from which side is output; for example, from the computer's screen output; STDERR is a data representing the output error from the computer, such as from the computer's screen output. In the Perl language, there are three standard FileHandle: (1) stdin: It behaves stdin FileHandle (2) stdout: is a FileHandle representing Stdout (3) stderr (Standard Error Output): Yes When you want to use other FileHandle when you want to use other filehandle, you can open a filehandle with the Open, we can use the print this function to output the List's data to FileHandle. . Before introducing this function, let's take a look at the special print symbol characters in the print function: Symbol Configuration / N Walking New Line / R Code Walk Return / T Tab Key / F Changes Form Feed / B Back Key Backspace / V vertical Tab key / A ring Bell / 007 decimal ASCII code / XFF hexadecimal code / C [control character example: print stdout "i love perl / n"; add "I love perl" plus The wrap is displayed on the screen. -------------------------------------------------- ------------------------------ Syntax 2: Print List Description: If FileHandle is omitted, you will define the FileHandle to stdout. That is, the data content of the LIST will be displayed on the screen. Example: $ str1ng = "perl"; print "i love $ string / n"; will add "I love perl" to the wrap on the screen, and if you want to invade the variables within the double quotes, you can in the variable Plus / this symbol. For example, if it is Print I love / $ string ";" I Love $ String "string will be displayed. --------------------------- -------------------------------------------------- --- Syntax 3: Print Description: I omit fileHandle and List, will use stdout as FileHandle, and output $ _ this memory output variable data content. If $ _ variable is an empty string If you show an empty string. Example: $ _ = "i love perl / n"; print; add "i love perl" plus the wrap display on the screen ----------------- -------------------------------------------------- ----------- Directive: Printf Syntax 1: Printf FileHandle List Description: In the Perl language, the syntax, usage and C language in the C language are also available in the Perl language. If you want to omit FileHandle, the STD0UT will be used as an end. FileHandle. Before introducing the printf function, let's take a look at the character of the transformed symbol in the printf function: the symbolical content% C character% S Strike% D integer% F float% h heel to code% O eight input code Example: Printf <"CHMOD% D% S \n", "7L1", "CGI"); will add "ChMOD 7ll CGI" to the screen. -------------------------------------------------- ------------------------------ Directive: Chop syntax: Chop ($ String) Description: Delete the last character, often Use this function to delete the charm characters (/ N). Example: $ String = "Hello! / N"; Chop ($ String); # This time $ String = "Hello!"; These two rows can also be written as a Chop ($ string = "hello! \N"); -------------------------------------------------- ----------------------------- Directive: Split Syntax: Split (/ Pattern /, $ String, Limit) where / patter is text The mode of processing will have a detailed grammar introduction in the next section. And LIMIT is the number of points to be divided, which can be omitted. Note: Use a specified text processing mode to split $ String strings. Example: $ String = "i; am; cute"; @ list = split (/: /, $ string); # @List = <"i", "am", "cute"); ($ A, $ b, $ c) = split (/: /, $ string); # This time $ a = "i", $ b = "am", $ c = "cute"; @ list = split (/: /, $ String, 2); # @List = ("I", "Love"); encoding the data before transmitting the CGI application data, where the data content of each data field in the Form will be used & This symbol is spaced apart, so in decoding, it is necessary to divide each data field in the decoding character. For example: $ String = "WHO = A & email = B"; @ list = split (/ & /, $ string), # @List = <"WHO = a", "email = b"); and data field The value of the name and this data field is separated from = this symbol. If you want to get the name of the data field and the corresponding value, use the data to = this symbol to divide the data. Fields, such as $ list = "WHO = A"; (0 $ name, $ value) = sp1it (/ = /, $ list); # = "who"; $ value = "a"; -------------------------------------------------- ------------------------------ Command: Keys Syntax: Keys (% array) Description: Take out all of the associated array% Array Key. Example:% names = (1, "one", 2, "two"); @ list = keys (% names), # @ list = (l, 2); -------------------------------------------------- ------------------------------ Command: VALUES Syntax: VALUES (% array) Description: Remove all of the associated array% Array Value. Example:% names = (1, "one", 2, "two"); @ list = values (% names); # @List = ("one", "two"); ------ -------------------------------------------------- ------------------------ Directive: Reverse Syntax: Reverse (@Array) Description: Re-arrange the elements in the array @Array. Example: @List = ("a", "b", "c", "d"); @ 1ist = reverse (@List); # @List = ("D", "c", "b" , "A") -------------------------------------------------- ------------------------------ Directive: Sort Grammar: Sort (@Array) Description: Put the elements in array @Array Small to large sorting, if you want to be sorted by big to small, you should add the REVERSE this function. Example: @Array = ("b", "c", "a"); @ array = sort (@Array); # @Array = ("a", b "," c "); @ array = (Reverse Sort @ array); # @Array = ("c", "b", "a"); this syntax can also be written into @ array = (Reverse sort (@Array)); @ Number = (L0, 3.20); @ Number = sort (@Number); # this time @ number = (L0, 20, 3); By the previous example, if you want the sort function to sort the value, you will make a mistake, so it is The following method can be sorted using the Sort function correctly. @ Number = (sort {$ a <=> $ b} @number); # @ Number = (3, 10, 20); -------------------------------------------------- ------------------------------ Directive: Length Syntax: Length ($ String) Description: String $ String BYTES value. Example: $ String = "Perl"; @ size = length ($ string); # s s = 4; -------------------------------------------------- ------------------------------ Command: Substr Syntax: Substr ($ String, Offset, Length) where OFFSET represents the start character The location, the length of the referenced string, such as omitting the last character length from the start value to the string. Offset If it is a negative value, take the specified string from the right side of the string. Description: Take the desired string in a string $ String. Example: $ x = substr ("Testing", 2, 2); # = "st"; $ x = Substr ("Testing", 2); # This time $ x = "sting"; $ x = SUBSTR ("Testing", - 2, 2); # = "in"; --------------------------- -------------------------------------------------- --- Command: Index Syntax: Index ($ String, $ Substring, Position) where $ substring refers to the characters you want to find, and the position represents which position begins to find, if you omit Position, you will start from the beginning. Description: Returns the position you want to find in a string $ String, if you can't find the character in the string, the -L is returned. Example: $ x = index ("Testing", "T"); # = 0; $ x = index ("Testing", "T", 2); # This time $ x = 3; $ x = Index ("Testing", "Perl"); # = -l at this time; -------------------------------------------------- ------------------------------ Directive: Push Syntax: Push (@ Array, $ String) Description: In array @Array At the last element, the new element string is added to the array @Array. Example: @Array = ("One", "Two"); Push (@Array, "Three"); # @Array = <"one", "two", "three"); -------------------------------------------------- ------------------------------ Directive: POP syntax: POP (@Array) Description: Put the last element of the array @Array Delete and returns the deleted element. Example: @Array = <"one" '"two"); $ RM = Pop <@Array); # @Array = ("one"); and $ RM = "Two"; -------------------------------------------------- ------------------------------ instructions: UNSHIFT Syntax: Unshift (@ array, $ string) Description: In array @Array Additional new elements in front of the first element to the set of $ string to the array @Array. Example: @Array = ("One", "Two"); unshift (@Array '"three"); # @Array = ("Three", "One", "Two"); -------------------------------------------------- ------------------------------ instructions: Shift syntax: Shift (@Array) Description: The first one of the array @Array Elements are deleted and the deleted element is returned. Example: @Array = ("One", "Two"); $ RM = Shift (@Array); # @Array = ("Two"), and $ rm = "one"; ------ -------------------------------------------------- ------------------------, instructions: join syntax: Join ($ string, @ array) Description: adds between a group of @Array elements The last specified character is $ String and returns the result. Example: @Array = ("One", "Two", "Three"); $ TOTAL = JOIN (":", @ array); # This time $ total = "one: two: three"; -------------------------------------------------- ------------------------------ instructions: grep syntax: grep (/ pattern /, @ array) Description: Will comply with text processing The array element of the REGULAR EXPRESSION is found. Example: @Array = ("One", "on", "in"); $ count = grep (/ on /, @ array); # at this time $ count = 2; (represents two elements) @Result = GREP (/ on /, @ array); # @Result = ("one", "on"); -------------------------------------------------- ------------------------------ Directive: HEX Syntax: HEX ($ String) Description: Turn the value of hexadecimal Come into ten. Example: $ decimal = HEX ("ff"); # # d d = 255; -------------------------------------------------- ------------------------------ Directive: RAND Syntax: Rand ($ Interger) Description: Common and function SRAND matches Random number, if there is no STAND function in advance, the value taken is a fixed value. This grammar returns a 0 and $ INTERG The value between the ER, if the $ INTERGER omit, a value of 0 and 1 is returned. Example: SRAND; # To first declare the SRAND function, can generate the effect of random number $ INT = rand (10); # $ int for greater than 0 and less than 10 If you want to generate the mess, you must add INT This function $ int = int (Rand (10)); # $ int value is an integer, and the value is between 0 and 9 -------------------------------------------------- ------------------------------ Command: Localtime Syntax: LocalTime (TIME) Description: You can return nine related time elements, This function will be described in detail here when writing CGI applications. Example: ($ Sec, $ MON, $ Year, $ WDAY, $ YDAY, $ ISDST) = localtime (time); where: $ sec represents the number of seconds [0,59] $ min Representative fraction [0,59] $ HOUR Agree number [0,23] $ mday representative is the first few days in this month [1,31] $ mon represents the month [0,11], to add $ MON plus L After that, it can be in accordance with the actual situation $ year from the year of the year. The first few days in this year [0,365] $ ISDST is just a FLAG knows these variables, it can be applied in the CGI application. In addition, you can use the following row instruction to obtain the system time under the UNIX system. In order to avoid errors, it is best to obtain the system time with the method of absolute path. If the absolute path is unclear, you can use "Which Date", this instruction. Finally, I want to remind the reader to use `this symbol. External programs that can perform UNIX systems, if you use '(single number) word symbols, you cannot correctly perform the system. $ DATE = `/ usr / bin / date`; in Perl5 version, you can also use the following line instructions to obtain system time. $ DATE = localtime (time); ------------------------------------------ -------------------------------------- Directive: DIE grammar: DIE List Description: Will put List The string is displayed and exits the program. Often and $! This represents the variable of the error message. Example: Open (File '"$ filename") || DIE "cannotopenfile $! / N"; if the file fails, the error message will be displayed, and then exit the program. -------------------------------------------------- ------------------------------ Directive: Open Syntax: Open (FileHandle '"$ FIIENAME") where $ FileName is a specified Open file name. Note: This is a very common function, which can be used for the Open Open (READ0NIY). A file is often opened in the CGI program design, so the author will add this letter. Related use. This FileHandle can regard it as a bridge between I (InPnt) / O (Output), which can use FileHandle to make actions written in data read. Start using OP EN This function opens a specified file, then you can use Open FileHandle. It should be noted that in the CGI program writing, when using the Open this function to open the file, be sure to add the absolute path name of the file before the open file. Example: $ filename = vpath / cgi.txt "; Open (file '" $ filename ") || DIE" Can not open $ filename\n "; # Assign data to the Pure Variable $ LINE (one line) While ($ line = In the file. Example: $ filename = "/ path / cgi.txt"; Open (file, "> $ filename") || DIE "can not open $ filename / n"; print file "this is a new line1 / n"; # / N is a wrap character print file "this is a new line2 / n"; close (file); there is a new file. -------------------------------------------------- ------------------------------ Grammar 4: Open (FileHandle, ">> $ filename") Description: Data is added Write Only, if the specified file name does not exist, a new file will be established. Example: $ filename = "/ path / cgi.txt"; Open (file, ">> $ filename") || DIE "can not open $ filename / n"; print file "this is a newline1 / n"; Print File "this is a newline2 / n"; Close (file); Append to a file (cgi.txt). -------------------------------------------------- ------------------------------ Syntax 5: Open (FileHandle, "| Unix Command") Description: Just put in FiieHandle The data output is processed to the UNIX instruction. Example: $ mailprog = "/ usr / ucb / mail"; #unix the sender (add absolute path!) $ WHO = "jcjung@tem.nctu.edu.tw"; open (file, " | $ mailprog $ ") || DIE" cannotfail! / n "; print file" I want to don't want me? / n "; print file" to reply a little! / n "; close (file); The Unix System Mail program gives the file of the FileHandle's data content to the received person specified by this variable. We can use the Open function to design a CGL app that comes to letter criticism, which will have a detailed introduction in the next chapter in this book. -------------------------------------------------- ------------------------------ Command: Close Usage: Close (FileHandle) Description: After using this function to open a filehandle Be sure to use a Close this function to turn the open FileHandle. Example: Open (FiieHandle, "$ filename"); Close (FileHandle); ------------------------------- ----------------------------------------------- Directive: PACK Syntax: PACK ("Specified Format", List) Description: Pack This function becomes a list into the specified binary data format. During the CGI program segmentation decoding process, the Pack this function will be used, so the author briefly introduces this Usage of functions. Example: $ String = Pack ("C", 65); # this time $ String = "a"; converts the 65 ASCII code into a unsigned character, where c is to specify what to convert to the unsigned character. -------------------------------------------------- ------------------------------ Command: read grammar: Read (FileHandle, $ String, Length) where Length is a representative read The length of the string (bytes). Description: Assigned this variable after reading the data in the FileHand1e by the READ1E, and assigned to the $ String variable after reading the data specified by the specified string. During the CGI program segmentation decoding process, if the form of forming is set to POST, the transmitted data is set to standard input, so the data content is specified to STD. In this standard input FileHandle, and the CGI environment variable $ env {'content_length'} is the length of the user who sends the data content, so we have to use Read. The data content sent by the user. Example: Read (stdin, $ buffer, $ env {'content_length'}); will read the data in the FileHandle in the fileHandle, and then assign this variable to $ Buffer in the specified string. -------------------------------------------------- ------------------------------ instructions: exit syntax: exit Description: Exit the executed program. Example: Print "I love perl"; exit; After "I Love Perl" is displayed, you immediately quit this program. -------------------------------------------------- ------------------------------ 6.3.3 Perl Language Operation Symbol Character The following is the computational characters commonly used in the Perl language, the computational characters in most and C languages are very similar, and those who have learned C language should be familiar with these operations characters. I. Assignment operator symbol sample Description = $ x = $ y; assign $ y's value to $ x = $ x = $ y; $ x = $ x $ y; will add $ x plus $ y Assign $ x - = $ x - = $ y; $ x = $ x- $ y; sending $ x $ y before assign $ x * = $ x * = $ y; $ x = $ x * $ y; assign $ x to $ y again to $ x / = $ x / = $ y; $ x = $ x / $ y; finding the $ x divided by the number after $ y, then assign $ 给 $ x ** = $ x ** = $ y; $ x = $ x ** $ y; Multiplying $ x) After each party, assign $ x% = $ x% = $ x = $ x % $ y; obtaining $ x After the remainder of $ y, assign $ x. = $ str1. = $ str2; $ str1 = $ str1. $ str2; add $ str1 this string plus $ STR2 After this string, assign $ str1 string x = $ str x = $ y $ str = $ str x $ y repeat $ STR string $ y and assigns the result to $ STR This string Second, the arithmetic operator symbol sample Description $ z = $ x $ y after adding $ x and $ y, then assign the result to $ z - $ z = $ x- $ x minus $ x After $ y, I will assign the result to $ z * $ z = $ y after multiplying $ x and $ y, and then assign the result to $ z / $ z = $ x / $ y will be except After $ y, the discivalent assignment gives $ z% $ z = $ x% $ x after $ y, then assign the remainder to $ z ** $ z = $ x ** $ y After $ Y, after $ y, the result is assigned to $ z $ x ; $ x is like $ x = $ x 1, add $ x to one after another will give the result to $ x - $ x -; - $ x As $ x = $ x-1, the $ x will be assigned to $ x. $ z = $ x. $ y will be $ x string and $ y string After the connection, the results are assigned to $ z. Numeric Values Relational Operator Symbol Example Description> $ x> $ y If $ x is greater than $ y, return 1 value, otherwise return 0> = $ x> = $ y If $ x is equal to $ y, return 1 value, otherwise return 0 <$ x <$ y if $ x is less than $ y, return the value of l, otherwise return 0 <= $ x <= $ y if $ x Less than or equal to $ y, return 1 value, otherwise return 0 == $ = $ y is equal to $ y, return to the value of L, otherwise return 0! = $ X! = $ Y is not equal to $ 不 $ Y, return 1 value, otherwise returns 0 <> $ x <=> $ y is greater than $ y, return 1 value; if $ x is equal to $ y, return 0; if $ x is less than $ y, Returns -1 value Fourth, string (StringValues) relational operator symbol sample Description GT $ str1 gt $ str2 If $ str1 is greater than $ STR2, return 1 value, otherwise return 0 GE $ STR1 GE $ STR2 If $ str1 is greater than equal to $ STR2, return 1 Value, otherwise return 0 lt $ str1 lt $ str2 If $ str1 is less than $ STR2, return 1 value, otherwise return 0 Le $ Strl Le $ str2 If the $ STRL is less than equal to $ STR2, return 1 value, otherwise return 0 EQ $ STRL EQ $ STR2 If $ strl is equal to $ str2, return 1 value, otherwise returning 0 NE $ str1 ne $ str2 If $ strl does not equal $ str2, return 1 value, otherwise return 0 CMP $ str1 Cmp $ str2 if $ str2 STR1 is greater than $ STR2, returns 1 value; if $ str1 is equal to $ STR2, return 0; if $ STR1 is less than $ STR2, return -1 value V. Logical Operators 1. $ x && $ y (and) $ x $ y Previous 真 (true) true (true) 假 (false) fake (false) (True) fake (false) fake (FALSE) 2. $ x || $ y (or) $ x $ y: true) true (TRUE) true (true) true (true) true (TRUE) true (TRUE) True) Fake (false) fake (FALSE) 3.! $ X (not) $ x Results (true) fake (false) true (TRUE) Sixth, other common operators --------------------------------------------------------------------------------------- ------------------------------------- Command: .. block operator (Range Operator) : This operator is a unique operator in the Perl language, which is a very practical operator. Example: @ digits = (1..9); # @ DIGITS = (L, 2, 3, 4, 5, 6, 7, 8, 9); @digits = ('10' .. '05' ); # @ Digits = (01, 02, 03, 04, 05); @char = ('a' .. 'e'); # @char = ('A', 'b', ' C ',' D ',' E '); @ Total = (L.3,' A '..' b '); # @ Total = (1, 2, 3,' A ',' B '); ----------------------------------------------- --------------------------------- Directive: Judging the arithmetic granulation? Arcurate 1: Computational 2 Conditional Operator ( Conditional Operator) Description: The meaning of this syntax is the same as the C language. If the value of the calculation is true (TRUE), the calculation 1 is calculated. If the discriminant operation is fake (false), the arithmetic 2 The calculation. Example: $ price = ($ AGE> 60)? 100: 200; if $ AGE is greater than 60, $ price is equal to 100; otherwise $ Price is equal to 200. --------------- -------------------------------------------------- --------------- Seven, common file data (File Test) operator example Description -R $ file if $ file is readable, return 1 value -w $ file if $ file is writable, return 1 value -X $ file if $ file is executable, return 1 value-E $ file exists, return 1 value -o $ file If $ file is being owned by the executor, return 1 value -s $ File Return $ File Size (Bytes) -f $ file If $ file is normal file, return 1 value - T $ file if $ file is a text file, return 1 value -b $ file if $ file is If the Billry file, the value returned 1 -M $ file returns the last change time of the File file to the current date 6.3.4 Perl Language Process Control The following is the program flow control, most and C language, which are commonly used in Perl languages, and people who have learned C language should be familiar. I. Selective process control ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------ instructions: if, if the grammatical one: if (discriminating the model) { Program Narrative block;} The previous grammatial can also be written in Perl: program narrative block IF (discriminant); example: Print "Please enter your score? / N"; $ score = -------------------------------------------------- ------------------------------