Learning notes for Perl-Chapter 3 1

Source: Internet
Author: User

Learning notes for Perl-Chapter 3 1

This article mainly introduces some arrays and lists, allowing you to fully understand the convenience and strength of Perl :)

Array:

1. The array is counted from 0.

2. Calculate the index value of the last element: $ # Rocks

3. Simply calculate the value of the last number: rocks [-1]

 

The range operator is used to indicate the direct quantity of the list:

(1. 5): 1, 2, 3, 4, 5

(5.7 ..): indicates that 1, 2, 3, 4, 5 decimal places are removed.

(): Empty list, only online count allowed

 

QW:

QW/Fred Barney Betty Wilma Dino /;

QW {

/Usr/local/words

/Home/rootbeer/. ispell_english

}

The QW operator can be used to easily define the list, and the front and back operators can be defined by themselves.

 

List assignment:

($ Fred, $ Barney, $ Dino) = ("Flintstone", "rubble", UNDEF );

Variable transformation method:

($ Fred, $ Barney) = ($ Barney, $ Fred );

Array assignment:

@ Rocks = QW/bedrock slate lava /;

Array replication:

@ Rocks = @ copy

 

Pop and push operators:

The pop function extracts the last element of an array and returns it:

@ Array = 5 .. 9;

$ Fred = POP (@ array); # $ Fred Get 9, @ array now has)

$ Fred = pop @ array; # $ Fred gets 8. Don't use the same brackets. @ array now has (, 6, 7)

The push function adds an element at the end of the array.

Push (@ array, 0); # Now @ array has (5, 6, 7, 0)

Push @ array, 8; # Now @ array has (5, 6, 7, 0, 8)

Push @ array, 1 .. 10; # @ array with 10 new elements added

Shift and unshift functions:

Operate on the beginning of the array, similar to pop and push;

@ Array = QW # Dino Fred Barney #;

$ A = shift (@ array); # $ A get Dino, @ array now ("Fred", "Barney ");

Unshift @ array, 4; # @ array now has 4, Fred, barney

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.