Get the array length by assigning the array variable to a scalar variable : Array Length « Array « Perl






Get the array length by assigning the array variable to a scalar variable

   

#!/usr/bin/perl -w

use strict;

my @array1;
my $scalar1;
@array1 = qw(Monday Tuesday Wednesday Thursday Friday Saturday Sunday);
$scalar1 = @array1;

print "Array 1 is @array1\nScalar 1 is $scalar1\n";

   
    
    
  








Related examples in the same category

1.Using a $#array variable in a loop.
2.Get array length
3.$# is the array size
4.$#questions is the index of the highest element in the @questions array.
5.The Array Size Indicator
6.Change array length by assigning new length to an array
7.Change array length by adding new element to an array
8.Increase the number of elements to 11
9.Reducing the number of elements to 6
10.Using scalar function to get the array length