## untested ## my @tables = qw (tb1 tb2 tb3); # DBI CONNECTION my $dbh = DBI->connect("dbi:Ingres:$dbname","$user","",{RaiseError => 1}) or die "Could not connect to database $dbname\n"; foreach my $table (@tables) { my $get_table = $dbh->prepare("SELECT * FROM $table"); $get_table->execute(); my $table_ref = $get_table -> fetchall_arrayref; open my $file, ">", "CSV$table.csv" or die "unable to open CSV$table.csv for writing $!"; print $file join(",", @{$table_ref->{NAME}}),"\n"; #show header - I'm not sure this works. print $file join(',',@$_),"\n" for @$table_ref; close $file; }