Perl | Getting the Number of Elements of an Array Last Updated : 18 Feb, 2019 Comments Improve Suggest changes Like Article Like Report An array in Perl is a variable used to store an ordered list of scalar values. An array variable is preceded by an "at" (@) sign. The size of an array can be determined using the scalar context on the array which returns the number of elements in the array Example 1: Perl #!/usr/bin/perl # Initializing the array @a = (1, 2, 3); # Assigning the array to a scalar # variable which stores size of # the array $s = @a; # Printing the size print "Size of the Array is $s"; Output: Size of the Array is 3 Above code returns the physical size of the array, not the number of valid elements. In order to obtain the maximum index of an array, '$#' is used as shown in the example below: Example 2: Perl #!/usr/bin/perl # Initializing the array @a = (1, 2, 3); # Store the value at any index # Let's take index 15 here, $a[15] = 20; # Printing the Array print "Array is @a"; # Getting the maximum index # of the array $i = $#a; # Printing the Max. Index print "\nMaximum index is $i"; Output: Array is 1 2 3 20 Maximum index is 15 Here is how the above code works:- Step1: Initializing an array with some values Step2: Assigning a value at any random index leaving the other indices blank Step3: Printing the array to show the blank spaces left in the array Step4: To get the maximum index '$#' is used Step5: Further, print the maximum index Comment More infoAdvertise with us Next Article Perl | Getting the Number of Elements of an Array R rupanisweety Follow Improve Article Tags : Perl Perl-Arrays Similar Reads How to get total number of elements used in array in PHP ? In this article, we will discuss how to get total number of elements in PHP from an array. We can get total number of elements in an array by using count() and sizeof() functions. Using count() Function: The count() function is used to get the total number of elements in an array. Syntax: count(arra 2 min read How to find the Total Number of Elements in an Array in TypeScript ? In TypeScript, arrays are a common data structure used to store collections of elements. You can store multiple elements of different or the same data type inside them by explicitly typing. The below methods can be used to accomplish this task: Table of Content Using the length property Using the fo 3 min read How to Get the Size of an Array in JavaScript To get the size (or length) of an array in JavaScript, we can use array.length property. The size of array refers to the number of elements present in that array. Syntaxconst a = [ 10, 20, 30, 40, 50 ] let s = a.length; // s => 5 The JavaScript Array Length returns an unsigned integer value that 2 min read How to Find Length or Size of an Array in Java? Finding the length of an array is a very common and basic task in Java programming. Knowing the size of an array is essential so that we can perform certain operations. In this article, we will discuss multiple ways to find the length or size of an array in Java.In this article, we will learn:How to 3 min read Batch Script - Length of an Array The length of the array is the number of elements in the array. The index of the array starts from "0" to "N-1" where N is a number of elements. For example arr[0]=1 arr[1]=2 arr[2]=3 Here we can see that the index starts from 0 and ends with 2 . So, we know that the index of the element goes from 0 2 min read Like