FreeKB - Perl Count values in an array
Perl - Count values in an array

Let's say you have an array that contains 4 values.

my @array = qw(value1 value2 value3 value4);


In this example, the $count variable will contain the number of elements in @array.

my $count = @array;


You can print the $count variable;

print $count;


Which will return 4, meaning there are 4 values in @array.



Additionsubtraction, division, and multiplication can be used to adjust the count, like this.

my $count = @array + 1;


Or like this.

my $count = @array;
$count = $count + 1;


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 73917 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |