I am trying to create multiple CSV files, which I'm going to use to input tables into Mysql (I had trouble writing code to put straight into mysql, and thought this would be easier for me to write, even if it is a bit convoluted) . The code compiles correctly and creates the files, but only the first file receives any data (and the first file goes into mysql fine).
use Text::CSV;
use IO::File;
my $GeneNumber = 4;
my @genearray;
my @Cisarray;
my @Cisgene;
$csv = Text::CSV->new ({ binary => 1, eol => $/ });
$iogene = new IO::File "> Gene.csv";
$iocis = new IO::File "> Cis.csv";
$iocisgene = new IO::File ">Cisgene.csv";
for(my $i=1; $i<=$GeneNumber; $i++)
{
@genearray=();
push(@genearray, 'Gene'.$i);
push(@genearray, rand());
push(@genearray, rand());
my $CisNumber=int(rand(2)+1);
for (my $j=1;$j<=$CisNumber;$j++){
@Cisgene=();
@Cisarray=();
push(@Cisgene, 'Gene'.$i);
push(@Cisgene, 'Cis'.$i.$j);
my $cisgeneref = \@cisgeneref;
$status = $csv->print ($iocisgene, $cisgeneref);
$csv->eol();
push (@Cisarray, 'Cis'.$i.$j);
push (@Cisarray, rand());
my $cisref = \@cisref;
$status = $csv->print ($iocis, $cisref);
$csv->eol();
}
my $generef= \@genearray;
$status = $csv->print ($iogene, $generef);
$csv->eol();
}
I am guessing the problem is something to do with
$status = $csv->print ($iocisgene, $cisgeneref);
I tried creating three versions of:
$csv = Text::CSV->new ({ binary => 1, eol => $/ });
however I still encountered the same problem.
Thanks