Using a $#array variable in a loop. : Array Length « Array « Perl






Using a $#array variable in a loop.

   

#!/usr/local/bin/perl 

@myarray = ("testing", 98.6, "Olerud", 47); 
for ($i = 0; $i <= $#myarray; $i++) { 
    print ("$myarray[$i]\n"); 
} 

   
    
    
  








Related examples in the same category

1.Get array length
2.$# is the array size
3.$#questions is the index of the highest element in the @questions array.
4.The Array Size Indicator
5.Change array length by assigning new length to an array
6.Change array length by adding new element to an array
7.Get the array length by assigning the array variable to a scalar variable
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