- my $cgi = CGI->new();
- my @rows = ();
- while (my $line = $sth->fetchrow_arrayref) {
- foreach (@$line) { defined($_) or $_ = ''; } # catch undef values, replace w/ ''
- push @rows, $cgi->TR( join('', $cgi->td($line)) ) . "\n";
+ my $message;
+ if ($format eq 'html') {
+ my $cgi = CGI->new();
+ my @rows = ();
+ while (my $line = $sth->fetchrow_arrayref) {
+ foreach (@$line) { defined($_) or $_ = ''; } # catch undef values, replace w/ ''
+ push @rows, $cgi->TR( join('', $cgi->td($line)) ) . "\n";
+ }
+ $message = $cgi->table(join "", @rows);
+ } elsif ($format eq 'csv') {
+ my $csv = Text::CSV_XS->new({
+ quote_char => $quote,
+ sep_char => $separator,
+ });
+ while (my $line = $sth->fetchrow_arrayref) {
+ $csv->combine(@$line);
+# foreach (@$line) {
+# defined($_) or $_ = '';
+# $_ =~ s/$quote/\\$quote/g;
+# $_ = "$quote$_$quote";
+# } # catch undef values, replace w/ ''
+# $message .= join ($separator, @$line) . "\n";
+ $message .= $csv->string() . "\n";
+ }