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