title: Perl print output file names with number variable
body: <p>I am trying to pull 1 week data from sql server, then trying to write the data into files with separate names.
  Following codes does not work, and I cannot find a way to create file handlers with a variable.</p>
  
  <p>Another question is that if the size of sql data is huge (1-2 gigabyte per day, and the entire table is over 1 year period), then is this monthly fetching method is faster than daily fetching?</p>
  
  <pre><code>    my $sqlGetEid = "select trunc(datetime, 'DD') truncdate, x, y from z
          where DATETIME between TO_DATE('$dt1','YYYY-MM-DD') and TO_DATE('$dt1','YYYY-MM-DD')+7";
  
      for ($day=1; $day&lt;=7; $day++){
          open('dayfile_$day', "&gt; ./temp/Wireless_$day.csv");  
      }
  
      while ( my ($tday,$x,$y) = $curSqlEid-&gt;fetchrow_array() ) 
      {
          printf {'dayfile_$tday'} ("%s,%d\n", $x,$y);
      }
  
      for ($day=1; $day&lt;=7; $day++){
          close('dayfile_$day');  
      }
  </code></pre>