PrimaveraTard
MIS
First off, my name says it all. I am a perl tard, so please bear with any stupid questions I may have.
I am trying to get the perl to spit out the contents of my database, comma seperated for backup purposes. Below is what I have. At the moment it spits out the data the way I want except for one problem, when the perl hits an empty field it stops and goes to the next row. I need perl to see the empty field and substitute an empty space in for the field so when I repopulate the database, it fills that field. Any help would be greatly appreciated.
#Create the SQL.
my $sql = qq{SELECT * FROM THIS_TABLE };
#Prepare the SQL and execute.
my $sth = $dbh->prepare( $sql );
$sth->execute();
#Fetch output rows into array, plus prepare a
#print formatter for the results.
while ( my(@thisString) = $sth->fetchrow_array) {
#Print out the result
my $x=0;
my $data="data.txt";
open(DAT,">>$data"
|| die("Cannot Open File"
;
printf DAT "$thisString[$x-1]%s", $x<=$#thisString ? ", ": "\n\n" while $thisString[$x++];
close(DAT);
}
$dbh->disconnect(); #Disconnect
I am trying to get the perl to spit out the contents of my database, comma seperated for backup purposes. Below is what I have. At the moment it spits out the data the way I want except for one problem, when the perl hits an empty field it stops and goes to the next row. I need perl to see the empty field and substitute an empty space in for the field so when I repopulate the database, it fills that field. Any help would be greatly appreciated.
#Create the SQL.
my $sql = qq{SELECT * FROM THIS_TABLE };
#Prepare the SQL and execute.
my $sth = $dbh->prepare( $sql );
$sth->execute();
#Fetch output rows into array, plus prepare a
#print formatter for the results.
while ( my(@thisString) = $sth->fetchrow_array) {
#Print out the result
my $x=0;
my $data="data.txt";
open(DAT,">>$data"
printf DAT "$thisString[$x-1]%s", $x<=$#thisString ? ", ": "\n\n" while $thisString[$x++];
close(DAT);
}
$dbh->disconnect(); #Disconnect