Multi-digit example code for Perl arrays _perl

Source: Internet
Author: User
Tags arrays

The normal subscript operation in the Perl array must be familiar to everyone, not to be explained here.
What this article is trying to say is that the majority of the subscript in the Perl array can be used to greatly facilitate the operation of the array.
Note: These numbers are from 0 to $ #array的.

Child array

Copy Code code as follows:

@array = (1, 2, 3, 4, 5);
@subarray = @array [0,1]; # @subarray = (1, 2)
@subarray2 = @array [1..3]; # @subarray2 = (2,3,4)
@array [0,1] = ("string", 46); # @array = ("string", 46,3,4,5) now
@array [0..3] = (11, 22, 33, 44); # @array = (11,22,33,44,5) now
@array [1,2,3] = @array [3,2,4]; # @array = (11,44,33,5,5) now
@array [0..2] = @array [3,4]; # @array = (5,5, "", 5,5) now

You can exchange elements in the form of a sub array:

Copy Code code as follows:

@array [1,2] = @array [2,1];

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.