use strict; use warnings; use DBI; my @clumps=( {table=>'tb1',file=>"csvfile1.csv"}, {table=>'tb2',file=>"csvfile2.csv"}, {table=>'tb3',file=>"csvfile3.csv"} ); my $dbname='a'; my $user='b'; # DBI CONNECTION my($dbh) = DBI->connect("dbi:Ingres:$dbname","$user","") or die "Could not connect to database $dbname\n"; for my $clump (@clumps){ my ($sth) = $dbh->prepare('SELECT * FROM '.$clump->{table}) or die "Prepare failed: $DBI::errstr\n"; $sth->execute() or die "Prepare failed: $DBI::errstr\n"; open my $fh, ">raw", $clump->{file} or die $clump->{file}. ": $!"; $fh->print (join(",", @{$sth->{NAME}}), "\n"); #show header while (my @row = $sth->fetchrow_array()) { $fh->print (join(",", @row), "\n"); }; close $fh or die $clump->{file}.": $!"; $sth->finish(); } $dbh->disconnect(); #### my @clumps=[ {table=>'tb1',file=>"csvfile1.csv"}, {table=>'tb2',file=>"csvfile2.csv"}, {table=>'tb3',file=>"csvfile3.csv"} ];