Perl Study Notes No. 2

Source: Internet
Author: User

1. the array name can be the same as the scalar name. // if you are not afraid of being dizzy, use it =. =
2. The array is out of bounds only when the value is UNDEF.
3. underline only serves to divide long numbers
4. The index value of the last element of the array is $ # Array
5. Regions ~~ Negative index value supported! For example, for an array of three elements, the-1 index is the third, the-2 is the middle, and the-3 is the first.
6. A serious error occurs when the negative index is out of bounds... = fatal error!
7. List,... is the range operator (range operator), for example (1 .. 100), indicating 1 to 100, integer list
8. The left value in... should be smaller than the right value, otherwise it is null, for example (7 .. 1)
9. There is a simple way to enter the string list without entering a large number of quotation marks, that is, using QW, such as QW (One Two Three)
10. QW only treats them as single quotes, so it cannot use escape characters and scalar interpolation.
11. Annotations cannot be added to QW.
12. List value exchange, ($ one, $ two) = ($ two, $ one );
13. Use @ to reference the entire array, for example, @ Nums = QW (one two three); @ Nums = 1 .. 10;
14. An array cannot be a list element, because the list can only accept scalar values.
15. Support pop and push operations... $ what = pop @ num; // retrieve and return
16. Push @ Nums, 1 .. 10; @ Other = QW/5, 7 .. 9, 11/; push @ Nums @ other
17. Shift and unshift Operation Array header elements, compared to the last element of pop and push operations
18. An array can also be inserted into a double quotation mark string, which will be automatically separated by spaces. In fact, it is the $ symbol output, and its value is space.
19. The inserted array does not have spaces before and after the first element. You need to add it yourself.
20. foreach control variable array/list {statement}, such as foreach $ num (@ Nums) {++ $ num ;}
21. If the foreach control variable is omitted, Perl provides the default variable $ _.
22. Or $ _ is the default variable in Perl, for example, $ _ = '1, 2, 3, 4'; print; will output $ _
23. reverse sorts array elements in reverse order. note: If the return value is not assigned to a variable, this operation is meaningless. for example, reverse @ Nums; (this is meaningless, so @ Nums = reverse @ Nums ;)
24. Sort sorts arrays by ascii by default, which is the same as reverse.

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.