Sorry, this isn't really a perl-dbi issue per-se. but I don't know where
else to post this issue. I can't find a "Perl" mail-list. There's loads
of list, but no perl-general.
Anyway.. pulling data from SQL-server using perl-dbi to be formatted as
a CSV file.
I had to do some tweaking to the output to maintain the format which
postgressql likes.
eg:
"A","B","C",,"D","E"
(note the ,, which means a NULL value)
My current code is below however, I enabled warnings and strict and get
this.
Use of uninitialized value in length at
/home/gentoo/Desktop/postgres_loading/mssql_2_postgres_cvs.pl
line 195 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a
mistake. To suppress this warning assign a defined value to your
variables.
To help you figure out what was undefined, perl tells you what
operation you used the undefined value in. Note, however, that perl
optimizes your program and the operation displayed in the warning may
not necessarily appear literally in your program. For example, "that
$foo" is usually optimized into "that " . $foo, and the warning will
refer to the concatenation (.) operator, even though there is no . in
your program.
Use of uninitialized value in concatenation (.) or string at
/home/gentoo/Desktop/postgres_loading/mssql_2_postgres_cvs.pl
line 197 (#1)
"A","B",,"C"
Use of uninitialized value in length at
/home/gentoo/Desktop/postgres_loading/mssql_2_postgres_cvs.pl
line 188 (#1)
Use of uninitialized value in print at
/home/gentoo/Desktop/postgres_loading/mssql_2_postgres_cvs.pl
line 190 (#1)
Code Block:
==============
##
## We do the fetching of the returned values and then we perform some
formatting prior
## to output. We need to make sure that if we are at the last value, we
must omit the
## trailing comma (,) to make it of form "value1","value2",,"value4"
## We also need to check if the current value is a NULL (0 length), if
so, we just
## do not put a quote mark around it.
##
while ( @first = $sth->fetchrow_array )
{
# my $first = 0;
# my $counter = 0;
my $count = @first;
my $first = @first;
for ($counter = 0; $counter < $count; $counter = $counter + 1)
{
if ($counter == $count-1)
{
if (length($first[$counter]) == 0) <==line 188
{
print $first[$counter]; <== Line 190
} else {
print "\"$first[$counter]\"";
}
} else {
if (length($first[$counter]) == 0)
{
print $first[$counter].","; <==LIne 197
} else {
print "\"$first[$counter]\",";
}
}
}
print ("\n");
}
}
Thanks in advance..