title: How to copy data to an array in perl?
body: <p>I am trying access the data from the database and copy the data to an array. This is my code,</p>
  
  <pre><code>$sth = $dbh-&gt;prepare("SELECT * FROM abcd WHERE id=100 "); 
  $sth-&gt;execute;
  $N=$sth-&gt;rows;
  print "$N\n"; 
  while (my @row_val = $sth-&gt;fetchrow_array()){
    my ($uniqid, $time, $current, $id ) = @row_val;
    $y[k]=$current;
    $k++;
  }
  for ($k=0;$k&lt;$N;$k++) {
    print "$y[k]\t";
  }
  </code></pre>
  
  <p>But it displays the same value for all $y[k]. How to copy the data from database to an array in perl?</p>