Learning Perl like learning history textbooks

Source: Internet
Author: User

The first time I came into contact with Perl was in February October 2008. At that time, due to project reconstruction, I needed a lot of text operations, so I picked up the Perl language "text operations as my mission. Of course, the famous llama book, the fourth edition of <learning Perl>, takes me to get started.

However, because it is mainly for use, it is just a fast-food Learning, and there is no systematic understanding of Perl. In the past few years, many Perl scripts have been written in twos and threes, however, there are still some headaches for Perl's tianshu-style symbols. Often, if it is half written, you have to stop and look up a strange syntax or symbol, which interrupts your thinking. The Community has two pertinent comments on Perl: Perl is the write-only programming language, and Perl is difficult to learn, but once learned, it is quite convenient to use. I think these two points are based on the fact that Perl contains too many strange symbols, and only when you know these symbols are ready can you maximize the efficiency of Perl-so, learning Perl is like learning historical textbooks. It depends on reciting!

Based on the experience of the past two years, I have sorted out some of the symbols, usage, functions, libraries, and so on that I think are quite basic, however, it is very helpful to improve efficiency.

Data Operations
  • $-Declare and reference a variable using a scalar
  • @-Declare and reference a list. However, when accessing a list member, you must use $ listname [Index].
  • %-Declare and reference a hash table, but when accessing a hash Member, use $ hashname {key}
Special Variables
  • $0-File Name of the currently running script
  • @ Argv-List of command line parameters for running the script
  • $ _-Default variables, such as the current variable in the loop
  • @_-Function input parameter list
  • % Env-System Environment Variables
  • @ INC-Perl include path list. We can add our own directories to this list to facilitate reference of custom libraries.
  • $!-Current System prompt, error message
  • $ ^ O-Operating System name
  • Stdin, stdout, stderr-Default handle of input and output, which can be customized
  • =>-When declaring a hash, it can be used to explicitly express the correspondence between key => value.
  • $ ^ I-Specifies the suffix of the backup file. In this way, the modified file will automatically save a copy with the suffix.
Special usage
  • & Sub-To call a function, although some Perl rules allow you to omit the & symbol here in some cases, they are considered for consistency. Therefore, I will use this method to call a custom function.
  • $ #-It is used to obtain the maximum index of the modulo array. In general, you can also use-1 to indicate the index of the last element.
  • QW ()-Quickly declare a string array, which can omit annoying quotation marks
Regular Expression
  • $ <Digit>-Get matching captured by parentheses
  • $ ', $ &, $'-Obtain the matched string and the first and second parts.
  • ^, $-Start position and end position of the string for positioning
Common functions
    • Pop, push, shift, unshift, reverse-List operation functions
    • Keys, values, exists, each, delete-Hash operation functions
    • Chomp, split, join, index, substr, sort-String operation functions
    • Sprintf, printf, print-Format the output function.
    • System, exec ,''-System commands call Functions
    • Glob, unlink, mkdir, rmdir, rename, chmod, chown, open, close, opendir, closedir-File System Operation Functions
    • Stat, lstat, localtime, gmtime, utime-Document attributes, time-related functions
    • Hex, Oct-Binary, octal, and hexadecimal Functions
    • Grep, map-List advanced operation functions

 

      For more information about these functions, run the following command:
1 perldoc -f functionname
    Check
Common Libraries
    • File: basename-Get the file name or file path based on path
    • File: spec-A path can be combined Based on the file name and path.
    • File: Find-Recursively traverse all files in a directory
    • XML: simple-Representation of XML files in a complex structure, which is quite convenient to use
    • Time: hires-It is often used to calculate the time required for an operation.
    • Getopt: Long-Used when the script requires complex input parameters and options
    • CWD-Get the current working directory
    • IO: File-File Operations
    • Win32-I will use it when I need to call some windows APIs.

Learning Perl like learning history textbooks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.