Count Item in an Array

To get the number of items in an array, you can evaluate the array as scalar context.

my @array = ("Apple", "Orange", "Tomato");

my $count = @array;
print $count;

Also scalar method can be used. This way seems more simple.

print scalar(@array);

 

Leave a Reply

Required fields are marked *.


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Top