Perl string and sorting

Source: Internet
Author: User

Index (primary string, substring) starts from 0 and returns the position of the most recent substring in the primary string.

Rindex (Main string, sub-string) Searches from the end and returns the position of the most recent sub-string in the main string.

You can accept the third parameter, indicating that the user starts searching. The default value is from 0 or the last

Substr operation substring

Three parameters: a string, an initial value from scratch, and the length of the sub-string returned value is a sub-string

If the second parameter is a negative value, it is the number starting from the end. The first parameter at the end is-1, followed by-2 to the left,-3...

If the third parameter is omitted, it starts from the second parameter to the end of the string.

Substr ($ big, 0, 5) = "zhouxiang" to perform this operation will change the original string.

Only the part of the string can be operated.

You can also take the part to be assigned as the fourth parameter to achieve the same effect.

Sprintf and printf have the same parameters, but sprintf returns the string to be requested instead of outputting it

 

Advanced sorting

Similar to the compareable interface in Java

You only need to specify the order relationship between the two elements to be sorted.

$ A <$ B-1

$ A> $ B 1

$ A = $ B, $ A and $ B do not distinguish size 0

Usage

Sort subroutine data

Note: Generally, child routines are named _.

Shorthand

Compare the number spacecraft operator <=> and return-1, 0, 1.

String CMP

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.