Because you have SELECT * .. the column names in the hash are probably lower case. You can add a print join " ", keys %$row line to check this. To fix it I would define the column names in the SELECT and use fetchrow_array like this
#!perl
use warnings;
use strict;
use DBI;
my @col = qw(RECORD SUBSCRIPT ID_SUBSTN CO_SUBSTN
AREA_SUBSTN ID_DEVTYP ID_DEVICE NAME_DEVICE
AREA_DEVICE ID_MEAS ID_POINT SITE_POINT AREA_POINT);
my $cols = join ",",@col;
# Create connection string to database point.csv
my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
f_ext => ".csv/r",
f_encoding => "utf-8",
});
my $sth = $dbh->prepare ("SELECT $cols FROM point
WHERE ID_DEVTYP LIKE 'INTELI%'
AND ID_POINT LIKE 'AUTO%'");
$sth->execute;
# Create AFS CSV with Columns
open DAT_OUTPUT,'>','AFS.csv' or die "Could not open AFS.csv : $!";
print DAT_OUTPUT $cols."\n";
# Cycle through SQL results on ROW basis and print to AFS CSV file
while (my @row = $sth->fetchrow_array) {
print DAT_OUTPUT (join ",",@row)."\n";
}
# Close file
close DAT_OUTPUT;
poj
-
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.
|