in reply to Re: Writing Multiple Recordsets into a CSV file
in thread Writing Multiple Recordsets into a CSV file

I am using the following code as per your suggesstion now:
#!/cluster/uapp/perl/bin/perl -w use KAP; use strict; use Date::Manip; use DBAccess; use EQ_Misc; use DBD::CSV; use MIME::Lite; use Net::SMTP; my $_db_lv_conn_file = "MSLV.eq_script_user"; my $_read_dbi = undef; # Run stored proc my $sp = "lv..check_tax_lot"; KAP::write_log("Preparing $sp"); $_read_dbi = KAP::opendbi($_db_lv_conn_file) || handle_error_and_e +xit ("Failed to get a connection to MSLV db server"); my $_read_sth = $_read_dbi->prepare($sp); if($DBI::err) { handle_error_and_exit("**ERROR preparing $sp: " . $DBI::errstr +); } KAP::write_log("Prepare done, executing $sp"); $_read_sth->execute(); if($DBI::err) { handle_error_and_exit( "**ERROR executing $sp: " . $DBI::errst +r); } KAP::write_log("Execute of $sp done"); my $_datafile = KAP::datafile(); my $numrecords = 0; my @data = undef; open my $fh, q{>}, $_datafile or die qq{cant open $_datafile to wr +ite: $!\n}; my $header_rec = join(",", @{$_read_sth->{NAME}}); # print the header to the filehandle print $fh $header_rec . "\n"; while (@data = $_read_sth->fetchrow_array) { # lets see what we have die @data; my @data = EQ_Misc::arr_replace_undef("", @data); my $csv_record = join(",", @data); # you're writing the array _and_ the record (and a dot)? #print $fh "@data $csv_record .\n"; # did you mean? print $fh qq{$csv_record\n}; } #close $datafile; close $fh;
The output is as follows:
nbsda1@vcstest3 $ perl test.pl
Name Age
John 29
Ram 30
at /cluster/uapp/app/bin/sudip.pl line 45.

#It still returns me only only the 1st Results set and discrads the last 6.

nbsda1@vcstest3 $
Please Help...

Replies are listed 'Best First'.
Re^3: Writing Multiple Recordsets into a CSV file
by apl (Monsignor) on Apr 10, 2008 at 11:35 UTC
    Are you certain that $_read_sth->fetchrow_array returns more than one record? A print STDOUT "@csv_record\n"; will show that.

    If it doesn't, then there's probably a problem with your stored procedure.