Just a side note: you are generating both invalid and probably even unparseable CSV. In the header line, you are including spaces after the comma, causing the header fields to be seen as e.g. Amount ("<space>Amount"). I cannot believe that to be intentional. Inside the loop you just spit out all fields joined on ,. Please try to think what will happen if any of the dat contains a comma. Having amounts makes that highly likely. The US uses $ 2,000,000.00 other countries might use € 2.000.000,00. Try to think about your data consumer. Please use a CSV generator like Text::CSV_XS which makes your code not only correct, but also removes the need for extra undefined checks.
print $cgi->header (
-type => "text/csv",
-charset => "utf-8",
-attachment => "data.csv",
);
my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\r\n" });
$csv->print (*STDOUT, [ "Platform ID", "Processor ID",
"Transaction ID", "Date", "Settlement Date",
"Transaction type", "Status", "Amount", "First Name",
"Last Name", "Address1", "Address(cont.)", "City",
"State or Province", "Postal Code", "Country", "Phone",
"Email", "Processor response code", "MSC response code",
"IP Address", "CC Number", "Descriptor" ]);
foreach my $v (@a) {
my ($m_id, @r) = @$v;
$r[6] = $r[6] ? "succeeded" : "failed";
$csv->print (*STDOUT, [ @r, $descriptors{$m_id}{$r[0]} ]);
}
$dbh->disconnect;
Enjoy, Have FUN! H.Merijn
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.