Length and number of elements in Perl arrays

Source: Internet
Author: User
Tags scalar



The length of the Perl array and the number of elements $ #数组名---represents the subscript of the last element in the array, which equals the number of elements minus 1. The @ array name---Represents the number of elements in the array. $ scalar [email protected] Array name---assigns an array to a scalar variable, and the scalar gets the number of elements of the array. $ array name [array subscript]---This format can be taken out of the number

Length and number of elements in Perl arrays


$ #Array name ---Represents the subscript of the last element in the array, which equals the number of elements minus 1.
The @ array name---Represents the number of elements in the array.
$ scalar [email protected] Array name---assigns an array to a scalar variable, and the scalar gets the number of elements of the array.
$ array name [array subscript]---This format to remove the corresponding element in the array.
Example 1
#!/usr/bin/perl
My @arr = (1,2,3,4,5);
My [email protected];
My $len 2=$ #arr;
print "$len 1 \ n";
print "$len 2 \ n";
print "-------\ n";

(My $scalar 2) [Email protected];
print "$scalar 2 \ n";
print "-------\ n";

My @str = ("A", "B", "C", "D");
my $count = 1;
while ($count <[email protected]) {
Print "element $count: $str [$count -1]\n";
$count + +;
}
Operation Result:
[Email protected] perl]# Perl arrary-len.pl
5
4
-------
1
-------
Element 1:a
Element 2:b
Element 3:C
Element 4:d


Length and number of elements in Perl arrays


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.