Use a scalar variable as our subscript: : Array Scalar « Array « Perl






Use a scalar variable as our subscript:

    
#!/usr/bin/perl

use warnings;
use strict;
my @array = (1, 3, 5, 7, 9);
my $subscript = 3;
print $array[$subscript], "\n";
$array[$subscript] = 12;

   
    
    
    
  








Related examples in the same category

1.Convert array to scalar
2.Assigning An Array To A Scalar
3.Assign array variable to scalar variable
4.Split a scalar to create a list
5.Assign array value to a list of scalar variables
6.Assigning an array value to a scalar variabe
7.Reference single array element by using the $ not @
8.Scalar Data in an Array
9.Place scalar variables in lists and arrays.