Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jun 192010

Get array size in Perl


To get the size of array in Perl, you have two methods.

Sample code:

my @a = (1, 2, ,3);

1. By scalar context

my $size = scalar @a;

2. By special variable $#array

my $size = $#a + 1;

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>