title: Perl: How to assign a common value to undef elements in an array?
body: <p>I am building five arrays in perl like (null, null, 32, 54, null, 59). So I first put the values that I know at specific index and fill the others with null. I do this like this </p>
  
  <pre><code>my @p0_series, @p1_series;
  $p0_series[2] = "test";
  $p1_series[3] = "string";
  $p2_series[2] = "hello";
  $p3_series[2] = "hi";
  for($a = 0; $a &lt; 5; $a++) {
    if(!defined $p0_series[$a]) {
     $p0_series[$a] = null;
    }
  
    if(!defined $p1_series[$a]) {
     $p1_series[$a] = null;
    }
  
    if(!defined $p3_series[$a]) {
     $p3_series[$a] = null;
    }
  
    if(!defined $p4_series[$a]) {
     $p4_series[$a] = null;
    }
  
    if(!defined $p5_series[$a]) {
     $p5_series[$a] = null;
    }
  }
  </code></pre>
  
  <p>I am trying to reduce this code to simpler one but I am not able to use the variable name p0_series, p1_seires dynamically in a loop. I tried like </p>
  
  <pre><code>for($a=0: $a &lt;5; $a++ ){
  if(!defined $p$i_series[$a] ) {
   #  assign values;
  }
  }
  </code></pre>
  
  <p>Which is not working.  I am new to perl any help is appreciated. 
  Is it possible I can assign the null value to all the undef elements in the array in a simpler manner?</p>