I'll leave it to others to comment about using other modules to write csv files so proper quoting is performed and just discuss your imediate question

This is untested, demonstration code

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();
Notice how i used an array of hashes to contain the table name and outfile file, then cycled thru it to do each table/outfile file pair

Edit: Hippo was right "You've set @clumps as an arrayref but then treat as an array. Typo?"

he saw it as

my @clumps=[ {table=>'tb1',file=>"csvfile1.csv"}, {table=>'tb2',file=>"csvfile2.csv"}, {table=>'tb3',file=>"csvfile3.csv"} ];


In reply to Re: Multiple queries on DBI corresponding to multiple csv files? by huck
in thread Multiple queries on DBI corresponding to multiple csv files? by jtech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.