Perl Study Notes No. 13

Source: Internet
Author: User

1. $ where = index ($ big, $ small); the character position starts from 0. if the substring is found at the beginning of the string, index returns 0. if a character is followed, 1 is returned, and so on. if the substring does not exist,-1 is returned.

2. You can use the optional third parameter to request that it start to query from a later place. It will tell the index where it starts.

3. reverse search of rindex. The usage is the same as above.

4. $ part = substr ($ string, $ initial_position, $ length); a string, an initial position starting from 0 (similar to the return value of index), and the length of the substring. the returned value is a substring.

5. If you want to explicitly reach the end of a string, whether it is long or short, you can omit the third parameter.

6. The initial position can be negative, indicating starting from the end of the string (at this time,-1 indicates the last character)

7. The corresponding position selected in the string can be changed. If the string is a variable:

My $ string = "Hello, world !";

Substr ($ string, 0, 5) = "goodbye"; # $ string is now "Goodbye, world! "

8. in addition to assigning values to substr (the first time seems a little weird), you can also use a more traditional method to use susbtr: use four parameters, and the fourth parameter is the converted string. my $ previus_value = substr ($ string, 0, 5, "goodbye ");

9. the parameters of the sprintf function are exactly the same as those of printf (except for the optional file handle), but it returns the requested string instead of printed. this is very convenient for storing strings in a certain format into variables for future use, or you want to control the results more than the methods provided by printf.

10. <=> compare numbers, CMP compare strings!

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.