Chapter 3 list and array of perl Introduction

Source: Internet
Author: User
Tags scalar
Preface

Repeat the concept of singular and plural in Perl: Scalar represents the singular, while list and array represent the plural in Perl.
Definition:
List): An ordered set of metric quantities. ------- Storage scalar
Array (array): Stores the list of variables. -------- Store Variables
The preceding two are ordered sets. Each element in the array or list has an integer as the index. The number increases from 0 and 1 is added each time.
Note:The list and array can contain any number of elements. It can have at least no elements and can fill up all available memory. ---Adhere to the perl principle of "removing unnecessary restrictions".

1. Array

Array assignment:
Array elements are numbered by continuous integers, starting from 0, followed by 1.Array assignmentThe same is true,Automatic expansion-"unlimited" principle, sequential.
For example, $ fred [0] = "aa"; $ fred [1] = "bb"; $ fred [10] = "gg "; the array fred now has a total of 11 elements (continuous, automatic expansion), other array elements that are not assigned values are usedUndef Filling.
Array reference:The reference is similar to the preceding array format. Note the following:
(1) If the reference table below exceeds the end of the array, the corresponding value will be undef.
(2) Special array index value: reference the value of the last element of the array: $ # bianlaing_ming or $ bianliang_ming [-1] (you canTail Loop).

2. List

List quantity:Parentheses, separated by commas. For the number list, you can also use the range OPERATOR:".."This operator counts from the number on the left to the right, and Adds 1 (not the unified conversion of numbers into numbers) each time to generate a series of continuous numbers. For example, (1.7,..., 5.7) indicates a list of five elements, 1, 2, 3, 4, and 5.
Qw Abbreviation:Create a simple word list. QW indicates quoted by whitspace (UseBlankCircle guide,Single quotesSeparate the words (word )). It extracts words by embedding spaces as separators to form a list.
From the first chapter, we can see that the characters in single quotes represent themselves. Perl also allows you to use any punctuation marks as delimiters. Commonly used methods include:
Qw! Fred barney betty wilma dino!
Qw/fred barney betty wilma dino/
Qw # fred barney betty wilma dino #
Qw {fred barney betty wilma dino}
Qw [fred barney betty wilma dino]
Qw <fred barney betty wilma dino>
The preceding statements are equivalent to qw (fred barney betty wilma dino. -- This is more consistentPerl's motto: There are more than one method (There's more than one way to do it).
Qw Usage Details, can refer to: http://perlmeme.org/howtos/perlfunc/qw_function.html
Assignment of the list:
There are three assignment modes:
(1) {$ fred, $ barney, $ dino }={ "fil", "rub", "und"}; ------- one-to-one correspondence
(2) {$ fred, $ barney }={ "fil", "rub", "und" };--------- the left-less and right-more values are ignored.
(3) {$ fred, $ barney, $ dino }={ "fil", "rub"} ----- multiple variables on the left are set to undef.
Here is another method to reference the entire array: @ shuzuming (@: you can read it as "all of the": all, all ).

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.